BookmarkSubscribeRSS Feed
zaldarsa
Obsidian | Level 7

Hello!

I am trying to work out an efficient way to go about coding the Mediterranean Diet score in SAS. The scoring system I am using is as follows: 

The MedDiet score was calculated from 11 individual diet components scored between 0 and 5 points and then summed for a total score between 0 and 55. Points were assigned monotonically for increasing intake of nonrefined grains, fruits, vegetables, potatoes, legumes, fish, and olive oil and decreasing intake of red meat, poultry, and full-fat dairy. Because information was not available for olive oil, we calculated a ratio of monounsaturated to saturated fatty acid intake and divided this component into sextiles as described previously in a US population. We scored the ratio of monounsaturated to saturated fatty acid monotonically from 0 to 5 points, with a ratio ≥2 assigned the highest score in accordance with a Greek MedDiet. Alcohol was scored 0 for nonconsumption or a high intake (>4.5 drinks per day) to a maximum score of 5 for moderate consumption (up to 2 drinks per day).

I wanted to use proc rank to get sextiles as it is efficient when you are working with many variables. and assign scores of 0-5 accordingly . However, the problem with proc rank is that a value of 0 is usually grouped with other values as part of the lowest group. This is a problem for my scoring system since a value of 0 needs to be scored separately. Please let me know if you would like me to elaborate on anything or provide a clearer explanation. Thank you in advance for your help!

3 REPLIES 3
ballardw
Super User

Some example data and what the result is supposed to look like when finished would probably help.

 

When you have a process such as Proc Rank that does almost what you want it may be that the final solution is to take the output from Proc Rank to a data step and apply the additional logic.

 

Possibly initially create 5 groups and then modify the rank for specific values:

proc rank data=sashelp.class out=ranked groups=5;
  var height;
  ranks heightrank;
run;

data want;
   set ranked;
   /* suppose we want isolate heights
   less than 60 that would group with others
   in the Rank 0 */
   if height > 60 then heightrank=heightrank+1;
run;

 

zaldarsa
Obsidian | Level 7

Sure, I can give an example. I tried to apply the code you suggested using an array, but i know that I'm doing the array in correctly since the results aren't right.

*Creating Mediterranean diet scores;
proc rank data= data out=data2 groups=5;
var veggie0 veggie7 veggie20 fruit0 fruit7 fruit20 potato0 potato7 potato20 grains0 grains7 grains20 fish0 fish7 fish20 legume0 legume7
legume20 poultry0 poultry7 poultry20 dairy0 dairy7 dairy20 alcohol0 alcohol7 alcohol20 rmeat0 rmeat7 rmeat20 monosat0 monosat7 monosat20;
ranks rveggie0 rveggie7 rveggie20 rfruit0 rfruit7 rfruit20 rpotato0 rpotato7 rpotato20 rgrains0 rgrains7 rgrains20 rfish0 rfish7 rfish20 rlegume0 rlegume7
rlegume20 rpoultry0 rpoultry7 rpoultry20 rdairy0 rdairy7 rdairy20 ralcohol0 ralcohol7 ralcohol20 r_rmeat0 r_rmeat7 r_rmeat20
rmonosat0 rmonosat7 rmonosat20;
run;

For example, veggie0 (vegetable consumption from baseline) ranks are:
rank 0: 0-0.8 
rank 1: 0.90-1.10
rank 2: 1.20-2
rank 3: 2-4
rank4: 5-7
How I would like 0 to be its own category, and the other values grouped into 5 other groups.


*Making Changes to Proc rank output;
data data3;
set data2;
array meddiet veggie0 veggie7 veggie20 fruit0 fruit7 fruit20 potato0 potato7 potato20 grains0 grains7 grains20 fish0 fish7 fish20 legume0 legume7
legume20 monosat0 monosat7 monosat20;
do i=1 to dim(meddiet);
array rank rveggie0 rveggie7 rveggie20 rfruit0 rfruit7 rfruit20 rpotato0 rpotato7 rpotato20 rgrains0 rgrains7 
rgrains20 rfish0 rfish7 rfish20 rlegume0 rlegume7 rlegume20 rmonosat0 rmonosat7 rmonosat20;
do j=1 to dim(rank);
if meddiet(i)> 0 then rank(j)=rank (j)+1; 
end;
end;
run;

Please let me know if you would like me to clarify anything else!

zaldarsa
Obsidian | Level 7

Nvm I figured out what I did wrong. Thank you again for pointing me in the right direction!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 393 views
  • 1 like
  • 2 in conversation