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

Hi there,

 

Any one can help me on Perl regular expression:

 

Example:

 

data have;

input ID:$1. Words :$50.;

datalines;

 

A Googled

B G.O.L

C GOL

D "G O L"

;

run;

data test;

set have;

Check=prxmatch("/GOL|G.O.L|G O L/", words);

run;

 

The result I need is B,C,D but not A by using prxmatch

 

Thanks for help 🙂

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @Suzy_Cat  You have answered your question. What's the problem? Are you asking to subset?

 

data have;

input ID:$1. Words  $50.;

datalines;
A Googled
B G.O.L
C GOL
D "G O L"
;


run;

data test;

set have;

if prxmatch("/GOL|G.O.L|G O L/", words);

run;

 

 

 

 

View solution in original post

8 REPLIES 8
novinosrin
Tourmaline | Level 20

Hi @Suzy_Cat  You have answered your question. What's the problem? Are you asking to subset?

 

data have;

input ID:$1. Words  $50.;

datalines;
A Googled
B G.O.L
C GOL
D "G O L"
;


run;

data test;

set have;

if prxmatch("/GOL|G.O.L|G O L/", words);

run;

 

 

 

 

Suzy_Cat
Pyrite | Level 9

whoops my bad, accidently put / instead of | between, no wonder it was not working earlier...

 

 

Check=prxmatch("/GOL|G.O.L/G O L/", words);

 

 

also there is an extra : when i tested earlier

 

data have;

input ID:$1. Words :$50.;

datalines;

 

A Googled

B G.O.L

C GOL

D "G O L"

;

run;

 

 

novinosrin
Tourmaline | Level 20

A precise regex would be

 

data test;

set have;
if prxmatch("/G(\.|\s)?O(\.|\s)?L/", words);

run;

checking for dot and blank whitespace char with ? making the check of the captured buffer optional 

Suzy_Cat
Pyrite | Level 9
@novinosrin, That is exactly what i wanted! Thanks heaps for the help out 🙂
novinosrin
Tourmaline | Level 20

Hi @Suzy_Cat  A further spice by not having create capture buffer 2 as we can back reference. I'm an idiot sometimes. 

 

So

 

data have;

input ID:$1. Words  $50.;

datalines;
A Googled
B G.O.L
C GOL
D "G O L"
;


run;

data test;

set have;
if prxmatch("/G(\.|\s)?O\1?L/", words);

run;
Suzy_Cat
Pyrite | Level 9
Even better! Noted down the formula for future usage.
ChrisNZ
Tourmaline | Level 20

What's the problem?

Maybe this is simpler?

CHECK = prxmatch('/G\W?O\W?L/', WORDS);

Suzy_Cat
Pyrite | Level 9

Thank you Chris,

 

Your suggestion is exactly what I was after...

🙂

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 8 replies
  • 1691 views
  • 5 likes
  • 3 in conversation