I recently coded a macro to create multiple "Proc freqs" easily, having to enter simply the variables and the condition "where" (if there is one). It generally works, still I've been struggling to make it work when my condition "where" contains an "AND".
Here's the macro:
options mprint minoperator;
%macro check(var1=,var2=,var3=, cond=);
Proc freq data= &dataset_full.;
Table &var1.
%if &var2. NE %str() %then
* &var2. ;
%if &var3. NE %str() %then
* &var3. ;
/ out="&var1. &var2. &var3." norow nocol nopercent;
%if &cond. NE %str() %then
&cond.;
;
Run;
%mend;
For instance, I could write %check(var1=age,var2=weight, cond=where age=1 and weight=10)
.
There would be no error, it just wouldn't apply my condition to the output. It's like "cond" was empty according to MPRINT output.
Conversely, if my condition contains "OR", it works fine.
I have tried using str(), %eval but it doesn't work.
If you use a data set where= option and force the user to pass the conditions in a parenthetical expression (same as what where= requires), macro will figure it out
Example:
The default
=(1)
will select all rows.