DATA Step, Macro, Functions and more

Re: Can i pass a complete where condition into a macro?

Reply
Regular Contributor
Posts: 227

Re: Can i pass a complete where condition into a macro?

reddyr1 wrote:

\begin{question}

%macro eye (eye,dat, id);

data adae ;

  set adamdata.adae;

  where &cond1;

    run;

%mend eye;

The where condition(in red color) needs to be modified for each table.

Eg: where ethnicity="Hispanic"

\end{question}

your problem is that you want to pass a string with an equals sign in it

as a parameter.

change from special character (=) to mnemonic (eq)

%macro eye (eye=,dat=, id=,cond1=);

%put &=cond1;

* ... where &cond1;

run;

%mend;

%eye(eye=,dat=,id=

,cond1=ethnicity eq 'Hispanic');

Super Contributor
Super Contributor
Posts: 3,174

Re: Can i pass a complete where condition into a macro?

Posted in reply to Ron_Fehd_macro_maven

Look at using the %quote(....) macro function to enclose your data-passed WHERE logic.

> suggested SAS.COM reference search argument:  pass quotes macro invocation site:sas.com

Scott Barry

SBBWorks, Inc.

Super User
Posts: 19,878

Re: Can i pass a complete where condition into a macro?

Posted in reply to Ron_Fehd_macro_maven

Yes, I asked a similar question a few weeks ago and it seems to work fine. I didn't have to mask anything.

https://listserv.uga.edu/cgi-bin/wa?A2=ind1506a&L=SAS-L&P=91498

Super User
Super User
Posts: 7,080

Re: Can i pass a complete where condition into a macro?

Posted in reply to Ron_Fehd_macro_maven

There is no need to change the parameter DEFINITIONS from positional to named, you can call position parameters by name.

%eye(eye=varx='blue')

You can also add () which should not impact the where clause.

Ask a Question
Discussion stats
  • 3 replies
  • 224 views
  • 1 like
  • 4 in conversation