I used code like this (see below) to pull the highest 5 scores out of a list of variables, and then I calculated the mean of the 5 highest scores.
array v{*} sd_1wk_1c sd_1wk_2c sd_1wk_3c sd_1wk_4c sd_1wk_5c sd_1wk_6c sd_1wk_7c sd_1wk_8c sd_1wk_9c sd_1wk_10c
sd_1wk_11c sd_1wk_12c sd_1wk_13c sd_1wk_14c sd_1wk_15c sd_1wk_16c;
array l{5};
do i=1 to dim(l);
l[i] = largest(i,of v(*));
end;
mdasisdhigh5_1wk=mean(of l1,l2,l3,l4,l5);
You can see the attachment to see what the resulting data look like.
Now I need to pull which 5 variables supplied the 5 highest values. That will tell me which of the 16 symptoms were the highest for each subject.
How would I do that?
Thanks!
Then you are going to have to get a different solution. The LARGEST() function just returns the values. Not where it came from.
Why not transpose the columns into rows to make it easier?
How do you want the five contributing variables to be presented? As names in other variables or?
Names of the variables would be okay, but variable labels would be even better.
Thanks!
Then you are going to have to get a different solution. The LARGEST() function just returns the values. Not where it came from.
Why not transpose the columns into rows to make it easier?
That helped. I was able to figure it out. Thanks!
Do something like this and work from there. Makes the whole thing much easier 🙂
data have(drop=i);
array v{*} sd_1wk_1c sd_1wk_2c sd_1wk_3c sd_1wk_4c sd_1wk_5c sd_1wk_6c sd_1wk_7c sd_1wk_8c sd_1wk_9c sd_1wk_10c
sd_1wk_11c sd_1wk_12c sd_1wk_13c sd_1wk_14c sd_1wk_15c sd_1wk_16c;
do _N_=1 to 10;
do i=1 to dim(v);
v[i]=rand('integer', 1, 10);
end;
output;
end;
run;
data long(keep=n idx score var);
set have;
array v{*} sd_1wk:;
n+1;
do idx=1 to dim(v);
score=v[idx];
var=vname(v[idx]);
output;
end;
run;
proc sort data=long;
by n descending score;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.