DATA Step, Macro, Functions and more

efficicient coding

Accepted Solution Solved
Reply
Contributor
Posts: 62
Accepted Solution

efficicient coding

Hello,

I have a dataset of patients who reported alcohol consumption during the last  3 months,see below

What would be the most efficient  way of coding the patients into  three categories

1- No alcohol drink during the last 3 months

2-moderate  alcohol consumption ( those who reported drinking 25 glasses per month)

3-Excessive alcohol consumption ( those who reported drinking more than 25 glasses  per month 

 

Thank you.

 

 

data alcohol;
  input ID month1 month2 month3;
  datalines;

30300003
30301336
30302000
30303103535
30390202221
30391000
3039292022
30393679045
30501121132
3050041219
30502242
30503122


;

 

 

 

 

 


Accepted Solutions
Solution
‎11-21-2016 04:00 PM
Respected Advisor
Posts: 4,644

Re: efficicient coding

[ Edited ]
mm = max(of month:);
if mm > 25 then cat = 3;
else if mm > 0 then cat = 2;
else cat = 1;
drop mm;
PG

View solution in original post


All Replies
Solution
‎11-21-2016 04:00 PM
Respected Advisor
Posts: 4,644

Re: efficicient coding

[ Edited ]
mm = max(of month:);
if mm > 25 then cat = 3;
else if mm > 0 then cat = 2;
else cat = 1;
drop mm;
PG
Contributor
Posts: 62

Re: efficicient coding

This is great!! Thank you very much.

One more question, if  the month variable was such as alco_month_1, alco_month_2, and alco_month_last, how can this be  tranformed mm = max(of month:) ?

Respected Advisor
Posts: 4,644

Re: efficicient coding

mm = max(of alco_month_:);
PG
Contributor
Posts: 62

Re: efficicient coding

Thanks!!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 175 views
  • 0 likes
  • 2 in conversation