/***************************************** This file uses the ordinal function on a set of array variables to get the largest 3 variables from a set. Since the ordinal function is weird for ties, this program puts in some fancy stuff for ties...so they won't be a problem. *********************************************/ options linesize=72; data test; input lpa1-lpa6 pck1-pck6; cards; 7 9 8 9 9 3 2 3 4 5 6 7 5 5 6 3 1 2 4 4 5 6 4 3 6 7 8 9 6 4 4 2 2 2 1 3 6 5 6 6 6 7 2 2 3 2 1 2 ; proc print data=test; title 'printout of original dataset'; data new; set test; array lpa(6) lpa1-lpa6; array pck(6) pck1-pck6; array tempvar(6) t1-t6; found=0; do i=1 to 6; if ordinal(6,of lpa(*))=lpa(i) and tempvar(i) ne 1 and found=0 then do; tempvar(i)=1; found=found+1; i1=i; end; end; do i=1 to 6; if ordinal(5,of lpa(*))=lpa(i) and tempvar(i) ne 1 and found=1 then do; tempvar(i)=1; found=found+1; i2=i; end; end; do i=1 to 6; if ordinal(4,of lpa(*))=lpa(i) and tempvar(i) ne 1 and found=2 then do; tempvar(i)=1; found=found+1; i3=i; end; end; proc print data=new; title 'printout of new dataset'; run;