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

Hello.

 

I have a dataset with 16 variables where subjects rate their symptoms (values from 0 to 10).

 

Now, for each subject, I need to use SAS code to identify the 5 variables where they rated their symptoms the highest.  I need to perform a calculation for each subject using those 5 variables only.

 

How would I do this?

 

I appreciate any help that you can provide.

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

This is really going to need some example starting data, fake is fine as long as it is representative of what you have, and what you expect the result to look like afterward.

 

 

What KIND of calculation do you mean to do?

 

This code will take the 5 largest values from 16 variables v1-v16 (since you provided no variable names replace with your variables) and place them from largest to smallest in variables L1-L5;

data want;
   set have;
   array v v1-v16;
   array l{5};
   do i=1 to dim(l);
      l[i] = largest(i,of v(*));
   end;
run;

If you need to know which variable contributed which value you need to provide more information on what you are doing.

 

View solution in original post

8 REPLIES 8
PeterClemmensen
Tourmaline | Level 20

First of all, provide some example data to get a usable code answer.

 

Secondly, what do you mean by "where they rated their symptoms the highest"? Does highest mean the sum of the entire variable or?

hein68
Quartz | Level 8
The subject enter a number from 0 to 10 for each variable.



Of the 16 variables for symptoms, for each subject I need SAS to determine which of the 5 variables had the highest ratings (i.e., 10 or closest to 10). I need to do calculations on the 5 highest values for each subject.



Thanks!


Reeza
Super User

It depends on your data structure. 

 

Can you show a sample of what you have and what you expect as output?

 

 

ballardw
Super User

This is really going to need some example starting data, fake is fine as long as it is representative of what you have, and what you expect the result to look like afterward.

 

 

What KIND of calculation do you mean to do?

 

This code will take the 5 largest values from 16 variables v1-v16 (since you provided no variable names replace with your variables) and place them from largest to smallest in variables L1-L5;

data want;
   set have;
   array v v1-v16;
   array l{5};
   do i=1 to dim(l);
      l[i] = largest(i,of v(*));
   end;
run;

If you need to know which variable contributed which value you need to provide more information on what you are doing.

 

hein68
Quartz | Level 8
This the 5 highest values, which I can then do the calculation on!



Thank you!!


ghosh
Barite | Level 11

What kind of calculation would you do on  ordinal variables?

Reeza
Super User
Means, Medians and Modes are common for likert data.
SuryaKiran
Meteorite | Level 14

If you need the variables that instead of the values, then i suggest transpose the dataset and sort descending and take the first 5 values.

 

data test ;
input val1-val10;
datalines;
1 2 3 4 5 6 7 8 9 10
;
run;
proc transpose data=test out=tr ;
run;

proc sort  data=tr;
by descending col1;
run;
data var_max;
set tr;
if _n_<=5;
run;

Please provide more information to  be more specific;

Thanks,
Suryakiran

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!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 8 replies
  • 4386 views
  • 8 likes
  • 6 in conversation