To answer post @ Jan 19, 2011 11:13 AM
>I am just curious if there is an equivalent way in proc sql.
There is: operators =: or in: can be used to subset a sas table in a sql statement if they are used as a dataset option instead of a sql clause.
proc sql;
select NAME from SASHELP.CLASS(where=(NAME in:('A','B')));
quit;
SAS macro approach suggested by @advoss:
The original request referred to the string being "CONTAIN"ed in the variable. The existing solutions have found it when the variable started with the string and didn't ignore case. If those two criteria are required, the following code accomplishes that.
data allstrings; input string $3.; cards; red al ber ; proc sql noprint; select 'lowcase(name) contains '''||trim(lowcase(string))||'''' into :strings separated by ' or ' from allstrings order by 1; create table subset as select * from sashelp.class where &strings; quit;
proc sql;
select *
from sashelp.class
where name in ('Alfred', 'Alice', 'Robert');
quit;
/* on lst
Name Sex Age Height Weight
-------------------------------------------
Alfred M 14 69 112.5
Alice F 13 56.5 84
Robert M 12 64.8 128
*/
proc sql;
create table names (name character(20));
insert into names set name="Al";
insert into names set name="Robert";
select c.*
from sashelp.class as c, names as n
where c.name eqt n.name;
quit;
/* on lst
Name Sex Age Height Weight
-------------------------------------------
Alfred M 14 69 112.5
Alice F 13 56.5 84
Robert M 12 64.8 128
*/
To answer post @ Jan 19, 2011 11:13 AM
>I am just curious if there is an equivalent way in proc sql.
There is: operators =: or in: can be used to subset a sas table in a sql statement if they are used as a dataset option instead of a sql clause.
proc sql;
select NAME from SASHELP.CLASS(where=(NAME in:('A','B')));
quit;
SAS macro approach suggested by @advoss:
The original request referred to the string being "CONTAIN"ed in the variable. The existing solutions have found it when the variable started with the string and didn't ignore case. If those two criteria are required, the following code accomplishes that.
data allstrings; input string $3.; cards; red al ber ; proc sql noprint; select 'lowcase(name) contains '''||trim(lowcase(string))||'''' into :strings separated by ' or ' from allstrings order by 1; create table subset as select * from sashelp.class where &strings; quit;
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.