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

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

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;

 

PG

View solution in original post

3 REPLIES 3
PGStats
Opal | Level 21

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;

 

PG
Ksharp
Super User
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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 3 replies
  • 1054 views
  • 1 like
  • 3 in conversation