%let food= SUV Sedan Sports ;
proc sql;
create table want as
select * from sashelp.cars
where findw(symget('food'),strip(type));
quit;
Ah that works nicely. Thank you
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.;
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.