BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ANKH1
Pyrite | Level 9

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!

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Amethyst | Level 16

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

3 REPLIES 3
yabwon
Amethyst | Level 16

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



ANKH1
Pyrite | Level 9

Thank you so much!

Quentin
Super User

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)

 

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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 lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1191 views
  • 2 likes
  • 3 in conversation