From many to one with specific order of new variables
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 | * From MANY lines to ONE line per case. * Code by Raynald Levesque rlevesque@videotron.ca. DATA LIST LIST /permnum(f8.0) sequence(f8.0) dept(a4) course(a4) ngrade(f8). BEGIN DATA 1 1 abc 301a 25 1 2 bcd 640c 35 1 3 fgh 222a 32 2 1 lkj 222b 11 2 2 poi 231g 88 END DATA. vector ndept(9a4). vector ncours(9a4). vector ngrad(9f8.0). compute ndept(sequence)=dept. compute ncours(sequence)=course. compute ngrad(sequence)=ngrade. aggregate /outfile=* /break=permnum /ndept1 to ndept9 = max(ndept1 to ndept9) /ncours1 to ncours9 = max(ncours1 to ncours9) /ngrad1 to ngrad9 = max(ngrad1 to ngrad9). execute. * Order variables as follows: permnum ndept1 ncours1 ngrad1 ndept2 etc. STRING a b c (A8). DO IF $casenum=1. WRITE OUTFILE='c:\\temp\\temp.sps' /'MATCH FILES FILE=* /KEEP=permnum'. LOOP #cnt=1 TO 9. COMPUTE a=CONCAT('ndept',LTRIM(STRING(#cnt,F8.0))). COMPUTE b=CONCAT('ncours',LTRIM(STRING(#cnt,F8.0))). COMPUTE c=CONCAT('ngrad',LTRIM(STRING(#cnt,F8.0))). WRITE OUTFILE='c:\\temp\\temp.sps' /" " a " " b " " c. END LOOP. WRITE OUTFILE='c:\\temp\\temp.sps' /". ". END IF. EXECUTE. INCLUDE FILE='c:\\temp\\temp.sps' . |
Related pages
...
Navigate from here