Expand data x and y times
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | I need to restructure a data set and create cases; I couldn't work out >a syntax that works that displays data in another file > >My original data set has the following structure (varF and varM are >simply gender frequencies) >varAge varF varM >20 1 2 >21 0 0 >22 1 0 >23 1 1 >24 0 1 > >but should ideally look like >varID varAge varGender (F=0,M=1) >001 20 0 >002 20 1 >003 20 1 >004 22 0 >005 23 0 >006 23 1 >007 24 1 DATA LIST LIST /varAge varF varM. BEGIN DATA 20 1 2 21 0 0 22 1 0 23 1 1 24 0 1 END DATA. LOOP cnt=1 TO SUM(varF,varM). + COMPUTE vGender=(cnt > varF). + XSAVE OUTFILE='c:\\temp\\data.sav' /KEEP=varAge vGender. END LOOP. EXECUTE. GET FILE='c:\\temp\\data.sav' . COMPUTE varId=$CASENUM. FORMATS varID (N3). LIST varID varage vgender.. *The result is: VARID VARAGE VGENDER 001 20.00 .00 002 20.00 1.00 003 20.00 1.00 004 22.00 .00 005 23.00 .00 006 23.00 1.00 007 24.00 1.00 * Note: because the end value of cnt is given in the LOOP command, the syntax works even when SUM(varF,varM) > MXLOOPS value. |
Related pages
...