11-22-2014 08:26 AM
I am new to SAS. While creating macros, I got stuck at how to call a macro conditionally.
I created a Macro for printing the dataset Blood. Now I need to call this macro only when Chol variable is greater than 200.
Please suggest how should I proceed in this case.
11-22-2014 08:47 AM
please go back to SAS macro-concepts.
In some languages like Excel a macro is smething like keybord recording.
In SAS the macro language is text processing of the SAS-source (code) to be processed by the interpreter (compile and go in one).
It makes no sense to ask for macros being executed conditionally.
Macros can be used for manipulating SAS source (code) conditionally.
SAS source(code) can be code in a way to treat the data conditionally (that is what programming is).
11-23-2014 09:54 AM
Conditional code generation is what a macro is good at.
You could either make the macro smart enough to determine if CHOL > 200 and conditionally perform the print.
Or you could add a parameter to the macro and pass in the condition.
%macro print_blood (dsname,print=yes);
%if print=yes %then %do;
proc print data=&dsname ....
%let print=no ;
proc sql noprint ;
select 'yes' into rint from MYDATA where chol > 200 ;