BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BonnaryW
Obsidian | Level 7

Hello,

 

I am looking for multple words within title.  I am not able to get this work. Please if you can help

 

data A;

input title $1-39;

 

datalines;

A TALE OF TWO CITIES

GENERAL MANAGER IN ONE CITY

MANAGER IS IN ANOTHER CITY

MANAGER IS NOT IN THE CITY

run;

data work;

set A;

WORD=FIND(title,("IS IN","IS NOT","i"); /**** "i" is to handle the case insensitive ****/

run;

1 ACCEPTED SOLUTION

Accepted Solutions
collinelliot
Barite | Level 11

Maybe a regular expression?

 

word = prxmatch('/is in|is not/i', title);

View solution in original post

6 REPLIES 6
collinelliot
Barite | Level 11

Maybe a regular expression?

 

word = prxmatch('/is in|is not/i', title);
BonnaryW
Obsidian | Level 7
Thank you so much, it's work !!!
PaigeMiller
Diamond | Level 26

I'm pretty sure you can only search for one string using FIND. What you want is something like

 

FIND(title,"IS IN","i") or FIND(title,"IS NOT","i") 
--
Paige Miller
BonnaryW
Obsidian | Level 7
Thank you so much. It's work !!!
ballardw
Super User

If you have many of these combinations to search for it may be better to create a data set with the target string and then use SQL to find the matches.

 

data work.find;
   infile datalines truncover;
   input find $10.;
datalines;
Is in
is not
in one
;
run;

data work.A;
   input title $1-39;
datalines;
A TALE OF TWO CITIES
GENERAL MANAGER IN ONE CITY
MANAGER IS IN ANOTHER CITY
MANAGER IS NOT IN THE CITY
run;

proc sql;
   create table matched as
   select a.*, b.find, find(a.title,strip(b.find),'i') as word
   from work.a as a, work.find as b;
quit;
BonnaryW
Obsidian | Level 7
Hello,
Thank you for replying with solution to my problem, I've accepted this answer as a solution.

word = prxmatch('/is in|is not/i', title);

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!

How to Concatenate Values

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.

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
  • 6 replies
  • 1221 views
  • 5 likes
  • 4 in conversation