| 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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.