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
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.