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