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

I want to select five character values within parentheses.   The first of 3 characters can be a letter or number and rest should be numbers.   This code correctly flags 'ABC(123)' but does not flag 'AZ(J11)' and incorrectly flags 'XYZ123'.   What do I need to change?

 

data a;
input x $10.;
datalines;
ABC(123)
AZ(J11)
ABZ(7)
XYZ123

XYY(1B1)
;
run;

data b;
set a;
flag=0;
if prxmatch('/[0-9]{3}/',x) then flag=1;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
ed_sas_member
Meteorite | Level 14

Hi @Batman 

You can try this:

 

 if prxmatch('/\([a-z|\d]\d\d\)/i', x) then flag=1;

a parenthesis \(

followed by a letter or a digit [a-z|\d] (nb: case insensitive -> I modifier)

followed by 2 digits d\d

followed by a parenthesis \)

 

 

View solution in original post

2 REPLIES 2
ed_sas_member
Meteorite | Level 14

Hi @Batman 

You can try this:

 

 if prxmatch('/\([a-z|\d]\d\d\)/i', x) then flag=1;

a parenthesis \(

followed by a letter or a digit [a-z|\d] (nb: case insensitive -> I modifier)

followed by 2 digits d\d

followed by a parenthesis \)

 

 

novinosrin
Tourmaline | Level 20

data a;
input x $10.;
datalines;
ABC(123)
AZ(J11)
ABZ(7)
XYZ123
XYY(1B1)
;
run;

data b;
set a;
Flag= ^^prxmatch('/\([a-z0-9]{1,3}\)/i',x);
run;

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
  • 2 replies
  • 653 views
  • 0 likes
  • 3 in conversation