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
Onyx | Level 15

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
Onyx | Level 15

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)

 

 

The Boston Area SAS Users Group is hosting free webinars!
Next up: Troy Martin Hughes presents Calling Open-Source Python Functions within SAS PROC FCMP: A Google Maps API Geocoding Adventure on Wednesday April 23.
Register now at https://www.basug.org/events.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 856 views
  • 2 likes
  • 3 in conversation