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;
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 \)
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 \)
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;
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!
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.