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

OK all-

So I am trying to figure out regular expressions and I am having a little bit of a challenge.

I am text mining a note field (that can have thousands of characters)-below is just one parameter that I am looking for-

I am looking for it to return a (or any)  value-but it just returns blanks-

Essentially I am looking for certain key phrases-

such as:

lungs are clear

lungs clear

lungs appear clear

Thanks in advance for your help-

Lawrence

data temp2;

set notes;

if _n_=1 then do;

re= prxparse('/lung\w{0,15}clear/');

if prxmatch(re,note_text) then ch=1;

end;

retain re;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
TomKari
Onyx | Level 15

I believe that the \w metacharacter won't include whitespace, such as blank or tab. Try a period (.) instead, like:

/lung.{0,15}clear/

Also, move your prxmatch function after your end;

Right now, you're only checking the first record.

I believe that your pattern will find "lungclear", which you might not want. If not, change it to {1,15}.

You're absolutely on the right track; you'll have it soon!

View solution in original post

3 REPLIES 3
data_null__
Jade | Level 19

\w does not find spaces.  This seems to work but I'm no RegXpert.

data temp2;

   input note_text $50.;

   if _n_=1

      then re= prxparse('/lung\w{0,15}|\s{1,5}clear/');

   if prxmatch(re,note_text) then ch=1;

   retain re;

   cards;

lungs are clear

lungs    clear

lungsclear

lungs appear clear

;;;;

   run;

proc print;

   run;

TomKari
Onyx | Level 15

I believe that the \w metacharacter won't include whitespace, such as blank or tab. Try a period (.) instead, like:

/lung.{0,15}clear/

Also, move your prxmatch function after your end;

Right now, you're only checking the first record.

I believe that your pattern will find "lungclear", which you might not want. If not, change it to {1,15}.

You're absolutely on the right track; you'll have it soon!

LB
Quartz | Level 8 LB
Quartz | Level 8

Thanks both of you!

Both solutions help although TomKari's answer works a tiny bit better.

Another question for you TomKari-

How can I set the first letter of lung to be either upper or lowercase?

Lawrence

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
  • 3 replies
  • 741 views
  • 3 likes
  • 3 in conversation