I'm using a macro. The input variables are like this:
%macro1(indata=din(where=group1=1 or group2=1)), outdata=dsout, var1=age);
I need to add another filter for indata. The condition is: if pair in(2,4,5) then delete;
I know I can do this in a data step, but I want to know if it is possible to add the condition in the macro parameters beside the where statement?
Thanks!
In situations like yours usually Maxim #4 helps...
The code:
data din;
group1=1;
group2=1;
do pair=1 to 10;
output;
end;
run;
%macro macro1(indata=, outdata=, var1=, additionalCondition=);
data &outdata.;
set &indata.;
&var1. = 42;
&additionalCondition.;
run;
%mend macro1;
%macro1(
indata=din(where=(group1=1 or group2=1))
, outdata=dsout
, var1=age
, additionalCondition=if pair in(2,4,5) then delete
)
Bart
In situations like yours usually Maxim #4 helps...
The code:
data din;
group1=1;
group2=1;
do pair=1 to 10;
output;
end;
run;
%macro macro1(indata=, outdata=, var1=, additionalCondition=);
data &outdata.;
set &indata.;
&var1. = 42;
&additionalCondition.;
run;
%mend macro1;
%macro1(
indata=din(where=(group1=1 or group2=1))
, outdata=dsout
, var1=age
, additionalCondition=if pair in(2,4,5) then delete
)
Bart
Thank you so much!
You could also add the filter to the WHERE option for the input daset:
%macro1(indata=din(where=((group1=1 or group2=1) and (pair NOT IN (2,4,5)) )), outdata=dsout, var1=age)
or add a WHERE option to the output dataset:
%macro1(indata=din(where=(group1=1 or group2=1)), outdata=dsout(where=((pair NOT IN (2,4,5)))), var1=age)
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.