pt ID | sex | service ID |
12 | M | 22 |
22 | F | 34 |
22 | F | 77 |
24 | M | 47 |
24 | M | 24 |
845 | F | 23 |
2384 | F | 99 |
4905 | M | 96 |
95 | M | 52 |
Could somebody help me create a macro that prints pt ID for any combination of sex and service ID? Service ID s go from 1 to 99.
I have an idea of how to do this but I wanna see if there is a better, more logical way.
Thank you in advance!
You don't need a macro, but here is one way to do it without a macro and one way using a macro:
proc print data=have (where=(sex eq 'M' and service_id eq 22)); var pt_id; by service_id sex ; run; /*or*/ %macro doit(sex,service_id); title "Patients with Gender = &sex. and Service_ID = &Service_ID"; proc print data=have (where=(sex eq "&sex" and service_id eq &service_id)); var pt_id; run; %mend doit; %doit(M,22)
Art, CEO, AnalystFinder.com
Not sure what you want. Do you want 99 records for every pt_id?
Art, CEO, AnalystFinder.com
If I correctly understand, you may only need something like:
proc sort data=have; by service_id sex ; run; proc print data=have; var pt_id; by service_id sex ; run;
Art, CEO, AnalystFinder.com
You don't need a macro, but here is one way to do it without a macro and one way using a macro:
proc print data=have (where=(sex eq 'M' and service_id eq 22)); var pt_id; by service_id sex ; run; /*or*/ %macro doit(sex,service_id); title "Patients with Gender = &sex. and Service_ID = &Service_ID"; proc print data=have (where=(sex eq "&sex" and service_id eq &service_id)); var pt_id; run; %mend doit; %doit(M,22)
Art, CEO, AnalystFinder.com
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.