is there a more efficient way to use contains than this: where classname contains 'ALGE' or classname contains 'ADV MATH' or classname contains 'MATH' or classname contains 'GEOME';
I tried where classname contains ('ALGE, 'ADV MATH etc) but i get an error.
Gregg, Are you possibly looking for something like:
data want;
set sashelp.class (where=(name in: ('A','H')));
run;
does that mean it would capture any class with 'A' or 'H' in the string or would it only get those that begin with A or H?
Only begins with. I apparently misunderstood what you were looking for.
Does it have to be in a where option? Would the following meet what you want?
data have;
informat ClassName $20.;
input ClassName &;
cards;
BASIC ALGEBRA
ALGEBRA II
BASIC MATH
NON ADV MATH
HISTORY
SCIENCE
;
data want;
set have;
retain pattern;
if _n_ eq 1 then pattern = prxparse("/ALGE|ADV MATH/");
if prxmatch(pattern,ClassName);
run;
Hi ... you need repeats of CONTAINS ...
data x;
input classname $30.;
datalines;
ENGLISH
ALGEBRA
ADV MATH
GEOMETRY
PHYSICS
WHAT'S IT ALL ABOUT ALGE
ADV MATERIALS
;
run;
data y;
set x;
where classname contains 'ALGE'
or
classname contains 'ADV MAT';
run;
classname
ALGEBRA
ADV MATH
WHAT'S IT ALL ABOUT ALGE
ADV MATERIALS
You can make a dataset to hold these index key, then use Cartesian Product of SQL.
NOTE: don't forget to use strip() function for index key.
data x; input classname $30.; datalines; ENGLISH ALGEBRA ADV MATH GEOMETRY PHYSICS WHAT'S IT ALL ABOUT ALGE ADV MATERIALS ; run; data index; input key $10.; cards; ALGE ADV MAT ; run; proc sql; select classname from x,index where classname contains strip(key); quit;
Ksharp
It's perfectly good and thanks so much
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.