BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
StaticFX
Obsidian | Level 7

Is it possible to pass in a Where? like...

 

%macro test(where);

proc sql;
   create table temp as
   select field1, field2 from tableA where &where;
quit;

%mend test;

%test("ap_period='1234'")
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Yes, but slightly easier if you use WHERE =

 

e.g

 

%macro test(where=);

proc sql;
   create table temp as
   select name, age from sashelp.class where &where;
quit;

%mend test;

%test(where= age=15);

@StaticFX wrote:

Is it possible to pass in a Where? like...

 

%macro test(where);

proc sql;
   create table temp as
   select field1, field2 from tableA where &where;
quit;

%mend test;

%test("ap_period='1234'")

 

View solution in original post

5 REPLIES 5
AhmedAl_Attar
Rhodochrosite | Level 12
Yes, but you will need to change your SQL into
where %unquote(&where);
StaticFX
Obsidian | Level 7

that simple?

lol guess i shouldve tried it first! Thanks! testing now

Reeza
Super User

Yes, but slightly easier if you use WHERE =

 

e.g

 

%macro test(where=);

proc sql;
   create table temp as
   select name, age from sashelp.class where &where;
quit;

%mend test;

%test(where= age=15);

@StaticFX wrote:

Is it possible to pass in a Where? like...

 

%macro test(where);

proc sql;
   create table temp as
   select field1, field2 from tableA where &where;
quit;

%mend test;

%test("ap_period='1234'")

 

StaticFX
Obsidian | Level 7

Bingo! the first way didnt quite work.. this works perfectly thanks!!

Tom
Super User Tom
Super User

Just wrap your condition inside of parentheses instead of quotes.  

%test((ap_period='1234'))

Also note that you can use named parameters in the macro call, even if the macro has it defined as a positional argument. 

You just can't try to pass a value by position when the parameter is defined as named in the %macro statement.

%test(where=ap_period='1234')

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 575 views
  • 4 likes
  • 4 in conversation