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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1179 views
  • 3 likes
  • 3 in conversation