BookmarkSubscribeRSS Feed
reddyr1
Calcite | Level 5

%macro eye (eye,dat, id);

data adae ;

  set adamdata.adae;

   if STUDYGR1 ='Y' and AECAT=&eye and TRTEMFL='Y'  and AEBODSYS ne '' 1 ; *'Ocular';

   where &cond1;

    run;

proc sql ;

                                /*Number of subjects TRTAN */

  create table any as select  trtan, count(distinct usubjid) as cnt from adae where trtan ne . group by  trtan;

  create table soc as select AEBODSYS,trtan, count(distinct usubjid) as cnt from adae where trtan ne . group by AEBODSYS,trtan;

  create table pt as select AEDECOD, AEBODSYS, trtan, count(distinct usubjid) as cnt from adae where trtan ne . group by AEDECOD,AEBODSYS,trtan;

  quit;

------

%mend eye;

The where condition(in red color) needs to be modified for each table.

Eg: where ethnicity="Hispanic"

where ethnicity="Not Hispanic"

where sex="Female"

where sex="Male"

where agegr1n=1

where agegr1n=2

where agegr1n=3

where agegr1n=4


I need to pass all these where conditions in one program.How can i do that?



1 REPLY 1
Reeza
Super User

Change the macro to have an additional parameter COND

Create a data set will the parameters you need to call the macro and use call execute

 

%macro eye (eye,dat, id, cond);

 

..

%mend;

 

Your PROC SQL tables will get overwritten with each run though as they will all have the same name.

 

My example of call execute:

https://gist.github.com/statgeek/beb97b1c6d4517dde3b2

 

SAS Documentation example for call execute:

http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000543697.htm

 

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
  • 1 reply
  • 1002 views
  • 0 likes
  • 2 in conversation