Solution ID: 100006487 Title: Removing 'empty' variables within a case Description: Q. I have loaded a data set that contains numerous missing values across variables. For instance of 10 multiple response variables, at most my respondents have answers for 4 of them. I would like to collapse my cases from 10 variables down to 4 variables to match the maximum number of responses in this data set. How do I do this. A. Previous solutions have shown the general techniques for 'collapsing' data from many records into a single record and for 'spreading' data from a single record into many records. The current problem requires both techniques. The following syntax illustrates the solution. Please copy and run this example in its entirety to understand the nature of the solution. * Read the SAMPLE data *. DATA LIST /x1 TO x10 1-10. BEGIN DATA 1 4 6 3 5 2 2 1 1 3 2 468 359 1 END DATA. LIST. * Identify cases *. COMPUTE id = $CASENUM. * Restructure many variable into one *. VECTOR x = x1 TO x10. LOOP rec = 1 TO 10. COMPUTE y = x(rec). XSAVE OUTFILE = 'tmp.sav' /KEEP id rec y. END LOOP. EXECUTE. GET FILE 'tmp.sav'. LIST. * Collapse empty cases and renumber cases within ID *. SELECT IF NOT(SYSMIS(y)). COMPUTE rec = 1. IF (id = LAG(ID)) rec = LAG(rec) + 1. LIST. * Restructure one variables into many *. VECTOR x(4). COMPUTE x(rec) = y. AGGREGATE OUTFILE = * /BREAK id /x1 TO x4 = MAX(x1 TO x4). LIST. * DONE! *. Created on: 04/29/1999