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...

🙂

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 8 replies
  • 995 views
  • 5 likes
  • 3 in conversation