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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.