BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hein68
Quartz | Level 8

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!

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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?

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

How do you want the five contributing variables to be presented? As names in other variables or?

hein68
Quartz | Level 8

Names of the variables would be okay, but variable labels would be even better.

 

Thanks!

Reeza
Super User
Look at the VNAME and VINFO functions.
Tom
Super User Tom
Super User

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?

hein68
Quartz | Level 8

That helped.  I was able to figure it out.  Thanks!

PeterClemmensen
Tourmaline | Level 20

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 6 replies
  • 916 views
  • 1 like
  • 4 in conversation