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))

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 18 replies
  • 2022 views
  • 5 likes
  • 7 in conversation