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)
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.