DATA Step, Macro, Functions and more

Can i pass a complete where condition into a dataset present within a macro?I need to use multiple where conditions for the same table which gives out multiple tables for each subgroup.Each where condition needs to use multiple variables.How can i do it?

Reply
N/A
Posts: 1

Can i pass a complete where condition into a dataset present within a macro?I need to use multiple where conditions for the same table which gives out multiple tables for each subgroup.Each where condition needs to use multiple variables.How can i do it?

%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?



Super User
Posts: 17,819

Re: Can i pass a complete where condition into a dataset present within a macro?I need to use multip

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

 

Ask a Question
Discussion stats
  • 1 reply
  • 155 views
  • 0 likes
  • 2 in conversation