%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))
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.