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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1700 views
  • 5 likes
  • 4 in conversation