* Each cases has many scores, objective is to identify the highest 3 scores of each case. * Posted by David Marso to comp.syst-soft.stat.spss on 03/24/1998. data list free / x1 to x10. begin data. 13 54 23 54 25 12 52 3 51 23 15 41 23 15 42 31 23 12 15 12 51 43 51 36 12 53 6 12 53 12 63 51 23 51 73 51 35 12 35 35 end data. ** ASSUMES THE DATA ARE POSITIVE **. ** TO JUST GET THE MAXIMUMS ** . VECTOR WHAT (3). loop #=1 to 3. COMPUTE WHAT(#)=MAX(X1 TO X10). * A FLAG TO TRAP TIES *. COMPUTE #FOUND=0. DO REPEAT X=X1 to X10 . DO IF X=WHAT(#) AND NOT #FOUND. * A LITTLE TRICK TO GET THE CURRENT MAXIMUM OUT OF THE WAY *. COMPUTE X=-X. * SO WE DON'T KILL ANY TIES * . COMPUTE #FOUND=1. END IF. END REPEAT. END LOOP. DO REPEAT X=X1 TO X10. IF X < 0 X=-X. END REPEAT. FORMATS ALL (F2.0). LIST. ** ANOTHER WAY ** . data list free / x1 to x10. begin data. 13 54 23 54 25 12 52 3 51 23 15 41 23 15 42 31 23 12 15 12 51 43 51 36 12 53 6 12 53 12 63 51 23 51 73 51 35 12 35 35 end data. * ASSUMES RELEVANT DATA ARE CONTIGUOUS BUT NOT NECESSARILY POSITIVE*. VECTOR X=X1 TO X10 / #(10) / WHAT (3). LOOP ##=1 TO 10. + COMPUTE #(##)=X(##). END LOOP. loop #=1 to 3. + COMPUTE WHAT(#)=MAX(X1 TO X10). + COMPUTE #FOUND=0. + LOOP ##= 1 to 10. + DO IF X(##)=WHAT(#). + COMPUTE X(##)=\$SYSMIS. + COMPUTE #FOUND=1. + END IF. + END LOOP IF #FOUND. END LOOP . LOOP ##=1 TO 10. + COMPUTE X(##)=#(##). END LOOP. LIST. ** TO GET MAXIMUMS AND THEIR LOCATION ** . VECTOR WHAT (3) / WHERE(3). loop #=1 to 3. COMPUTE WHAT(#)=MAX(X1 TO X10). COMPUTE #FOUND=0. DO REPEAT X=X1 to X10 / Ind = 1 TO 10. DO IF X=WHAT(#) AND NOT #FOUND. COMPUTE WHERE(#)=Ind. COMPUTE X=-X. COMPUTE #FOUND=1. END IF. END REPEAT. END LOOP. DO REPEAT X=X1 TO X10. IF X < 0 X=-X. END REPEAT. FORMATS ALL (F2.0). LIST.