Hello,
I would like to exclude the 'SUB' and 'NCV' in the PRXMATCH command. I have the code below. I found the texts are still in the result TEMPID. Please help. Thank you.
if prxmatch ('/000|^SUB|^NCV/i',id) then TempID=id;
Hi @ybz12003 Not sure your objective,
Assuming you are saying something like below is what you want
if id = '000' or id not in ('SUB','NCV') then tempid=id;/*assuming you want this*/
is literally equivalent to
if id not in ('SUB','NCV') then tempid=id;
which basically is equivalent to
if not prxmatch ('/SUB|NCV/i',id) then TempID=id;
I'm not entirely sure what you want to do here. Your code matches string that contain '000' or starts with either 'sub' or 'ncv' (case insensitive).
Hi @ybz12003 Not sure your objective,
Assuming you are saying something like below is what you want
if id = '000' or id not in ('SUB','NCV') then tempid=id;/*assuming you want this*/
is literally equivalent to
if id not in ('SUB','NCV') then tempid=id;
which basically is equivalent to
if not prxmatch ('/SUB|NCV/i',id) then TempID=id;
@ybz12003 wrote:
Hello,
I would like to exclude the 'SUB' and 'NCV' in the PRXMATCH command. I have the code below. I found the texts are still in the result TEMPID. Please help. Thank you.
if prxmatch ('/000|^SUB|^NCV/i',id) then TempID=id;
Please provide some sample data and then show us the desired result.
For your RegEx: Do you by any chance believe the ^ has a meaning of NOT?
^abc Here the ^ means beginning of string so strings starting with abc will match.
[^abc] Here the ^ has the meaning of NOT and string containing a, b, or c anywhere will not match
Below is my sample dataset.
data datain;
infile datalines dsd;
input Name : $300. ;
datalines;
0001234,
SUB0001031,
NCV0001234,
CARID0001070,
;
run;
The final result I want is 0001234 and CARID0001070.
Hi @ybz12003 Please check if this works
data datain;
infile datalines dsd;
input Name : $300. ;
datalines;
0001234,
SUB0001031,
NCV0001234,
CARID0001070,
;
run;
data want;
set datain;
where not prxmatch ('/^(SUB|NCV)/i',name);
run;
Like this?
where NAME not in: ('SUB','NCV') and index(NAME,'000');
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.