DATA Step, Macro, Functions and more

scan function for multple words

Accepted Solution Solved
Reply
Contributor
Posts: 30
Accepted Solution

scan function for multple words

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;


Accepted Solutions
Solution
‎04-05-2017 01:06 PM
PROC Star
Posts: 288

Re: scan function for multple words

Maybe a regular expression?

 

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

View solution in original post


All Replies
Solution
‎04-05-2017 01:06 PM
PROC Star
Posts: 288

Re: scan function for multple words

Maybe a regular expression?

 

word = prxmatch('/is in|is not/i', title);
Contributor
Posts: 30

Re: scan function for multple words

Thank you so much, it's work !!!
Trusted Advisor
Posts: 1,607

Re: scan function for multple words

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") 
Contributor
Posts: 30

Re: scan function for multple words

Thank you so much. It's work !!!
Super User
Posts: 10,466

Re: scan function for multple words

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;
Contributor
Posts: 30

Re: scan function for multple words

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);

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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