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

I am trying to run a where in proc sql clause where a character string is fed into the list.  When I feed the string in it errors out.  Am I using the right structure?

%let sumlev = 'AX', 'AH';

proc sql noprint;

where term ='Fall' and college in (&sumlev);

quit;

1 ACCEPTED SOLUTION

Accepted Solutions
FriedEgg
SAS Employee

This is fine, once you have valid SQL, anyway.

However, given your other post about adding the apostrophes, which used macro quoting, you need to %unquote() the macro variable for it to work correctly:

%let a=%str(%');

%let sex=&a.M&a.,'F';

proc sql;

select * from sashelp.class where sex in (%unquote(&sex.));

quit;

View solution in original post

5 REPLIES 5
FriedEgg
SAS Employee

This is fine, once you have valid SQL, anyway.

However, given your other post about adding the apostrophes, which used macro quoting, you need to %unquote() the macro variable for it to work correctly:

%let a=%str(%');

%let sex=&a.M&a.,'F';

proc sql;

select * from sashelp.class where sex in (%unquote(&sex.));

quit;

DavidPhillips2
Rhodochrosite | Level 12

Thanks for answering my questions about crazy quotes.  I’ve been doing a lot of work with quotes lately and it’s a learning curve.

Ksharp
Super User

Not need to use quote character . For your situation , use symget() would be better;

%let sumlev = AX AH ;

proc sql noprint;

where term ='Fall' and symget(sumlev)  contains strip(college) ;

quit;

FriedEgg
SAS Employee

One minor correction

symget('sumlev')

And yes, this will work and does not require the quoting or delimiting of the list and is viable with the example data (although may not be with your actual data, depending...)

Ksharp
Super User

Opps. Did you see Arthur.T before ?  He didn't appear here for a very long time.

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
  • 1868 views
  • 0 likes
  • 3 in conversation