BookmarkSubscribeRSS Feed
GreggB
Pyrite | Level 9

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.

7 REPLIES 7
art297
Opal | Level 21

Gregg,  Are you possibly looking for something like:

data want;

  set sashelp.class (where=(name in: ('A','H')));

run;

GreggB
Pyrite | Level 9

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?

art297
Opal | Level 21

Only begins with.  I apparently misunderstood what you were looking for.

art297
Opal | Level 21

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;

MikeZdeb
Rhodochrosite | Level 12

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


Ksharp
Super User

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

Jack2012
Obsidian | Level 7

It's perfectly good and thanks so much

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 948 views
  • 0 likes
  • 5 in conversation