Hi wonderful helpers,
I need your help here to select the right records using wild match function:
The data Want should only include records with PID contains A1|A7|A12
, i.e. only contains A followed by 1, 7 or 12:
data have;
infile datalines;
input PID $1-6 code $8 +1 date date9.;
datalines;
AAA12b 7 13Aug2012
AAA124 1 13Aug2012
AAA12a 5 13Aug2012
bbA1aa 1 14Dec2018
bbA723 2 14Dec2018
ggA7ab 4 23Apr2012
ggg7cd 0 23Apr2012
;
data have;
set have;
format date date9.;
run;
data want;
set have;
if prxmatch("/A1|A7|A12/", PID);
if upcase(PID) ~="AAA124";
if upcase(PID) ~="BBA723";
run;
Thanks in advance!
Use a negative look ahead assertion (?!...) in the match pattern and the i suffix (to make the match case insensitive):
data want;
set have;
if prxmatch("/A(1|7|12)(?!\d)/i", PID);
format date date9.;
run;
Use a negative look ahead assertion (?!...) in the match pattern and the i suffix (to make the match case insensitive):
data want;
set have;
if prxmatch("/A(1|7|12)(?!\d)/i", PID);
format date date9.;
run;
Thank you PGStats for explaining.
https://support.sas.com/rnd/base/datastep/perl_regexp/regexp-tip-sheet.pdf
data have;
infile datalines;
input PID $1-6 code date : date9.;
format date date9.;
datalines;
AAAA12 7 13Aug2012
AAA12b 7 13Aug2012
AAA124 1 13Aug2012
AAA12a 5 13Aug2012
bbA1aa 1 14Dec2018
bbA723 2 14Dec2018
ggA7ab 4 23Apr2012
ggg7cd 0 23Apr2012
;
data want;
set have;
if prxmatch("/(A1|A7|A12)\D/i", PID||' ');
run;
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.