SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

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;
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

 

 

View solution in original post

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

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).

novinosrin
Tourmaline | Level 20

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;

 

 

Patrick
Opal | Level 21

@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

 

ybz12003
Rhodochrosite | Level 12

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.

novinosrin
Tourmaline | Level 20

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;
ChrisNZ
Tourmaline | Level 20

Like this?

where NAME not in: ('SUB','NCV') and index(NAME,'000');

 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

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
  • 6 replies
  • 1650 views
  • 2 likes
  • 5 in conversation