BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ksharp
Super User


%let food= SUV Sedan Sports ;

proc sql;
create table want as
 select * from sashelp.cars
  where findw(symget('food'),strip(type));
quit;
mcook
Quartz | Level 8

Was shown this way to accomplish this as well.

 

Given the TestTable from my original post.

proc sql noprint;
	select '"'||strip(C)||'"' into :foods
		separated by ' '
	from TestTable;
quit;

%PUT Foods=&Foods.;

This also works with the distinct predicate. such as:

 

proc sql noprint;
	select distinct '"'||Strip(type)||'"' into :CarTypes
		separated by ' '
	from sashelp.cars;
quit;

%PUT CarTypes=&CarTypes.;

 

 

Tom
Super User Tom
Super User

Two problems with 

'"'||strip(C)||'"'

First is that using STRIP() instead of TRM() will remove any leading spaces from the values of C.  So that the quoted strings will now no longer match the value that is in the dataset.

Second is when the value of C contains quote characters.  You need to double any quote characters to make a valid string literal.

Better to use the TRIM() and QUOTE() functions.

quote(trim(C))

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 18 replies
  • 1583 views
  • 5 likes
  • 7 in conversation