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;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.