BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
K_S
Quartz | Level 8 K_S
Quartz | Level 8
pt IDsexservice ID
12M22
22F34
22F77
24M47
24M24
845F23
2384F99
4905M96
95M52

 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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

 

View solution in original post

6 REPLIES 6
art297
Opal | Level 21

Not sure what you want. Do you want 99 records for every pt_id?

 

Art, CEO, AnalystFinder.com

 

K_S
Quartz | Level 8 K_S
Quartz | Level 8
hmmm....nope. I have thousands of patients and 99 codes and 2 sexes.
so for every combination of sex and code, I want to print the pt IDs
for example I want to know the IDs of all the patients who are M and are in
for a 64 ( which is psychiatric services), and so on and so forth. A macro
could do this..

##- Please type your reply above this line. Simple formatting, no
attachments. -##
art297
Opal | Level 21

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

 

K_S
Quartz | Level 8 K_S
Quartz | Level 8
hmm...no, not what I am looking for. It has to be a macro that would allow
me to randomly pick combinations of sex and service IDs.
Let's say today I want to get the IDs of all the males who are in for a 64,
but then tomorrow I want to look at women who are in for a 52.
I am sorry if I am not making a lot of sense. I am new to this and not
entirely sure what I am being asked to do. All I know is that it has to be
a macro that would allow me to get pt_IDs for any combinations of sex and
service id.


##- Please type your reply above this line. Simple formatting, no
attachments. -##
art297
Opal | Level 21

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

 

K_S
Quartz | Level 8 K_S
Quartz | Level 8
This is beautiful! Thank you!
You just helped me understand something I completely missed. Much
appreciated 🙂

##- Please type your reply above this line. Simple formatting, no
attachments. -##

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2043 views
  • 1 like
  • 2 in conversation