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,

 

The prxmatch program below is searching the created macro list as 'CAR|IL|VN|KK'.   However, I would like the search be more restricted.   Instead of containing the ''CAR|IL|VN|KK'' string in the text,  I like to match 100% these two letters.   Please advice how to change this prxmatch codes.  Thank you.

 

if prxmatch ("/&Jurisdiction_list./i",id) then TempID=id;

The following sample data set is

data datain;
      infile datalines dsd;
  input ID : $300. ;
datalines;
	CAR ID  MA,
	ILH,
	PAUL  VN,
	KKK GGGG,
	Card ID BMA,
	Care ID FMA,
;

run;

 

The final result I am looking for is only at the 1st and 3rd row.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
%let Jurisdiction_list=CAR|IL|VN|KK;
data datain;
      infile datalines dsd;
  input ID : $300. ;
datalines;
	CAR ID  MA,
	ILH,
	PAUL  VN,
	KKK GGGG,
	Card ID BMA,
	Care ID FMA,
;

run;
data want;
set datain;
if prxmatch ("/\b(&Jurisdiction_list)\b/i",id) then TempID=id;
run;

ID TempID
CAR ID MA CAR ID MA
ILH  
PAUL VN PAUL VN
KKK GGGG  
Card ID BMA  
Care ID FMA  

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20
%let Jurisdiction_list=CAR|IL|VN|KK;
data datain;
      infile datalines dsd;
  input ID : $300. ;
datalines;
	CAR ID  MA,
	ILH,
	PAUL  VN,
	KKK GGGG,
	Card ID BMA,
	Care ID FMA,
;

run;
data want;
set datain;
if prxmatch ("/\b(&Jurisdiction_list)\b/i",id) then TempID=id;
run;

ID TempID
CAR ID MA CAR ID MA
ILH  
PAUL VN PAUL VN
KKK GGGG  
Card ID BMA  
Care ID FMA  
ybz12003
Rhodochrosite | Level 12

What is the '\b' for?  Why need to one at the front and one at the end? 

 

novinosrin
Tourmaline | Level 20

\b metacharacter is known as word boundary. When you mentioned "absolute" match of a word, my thought went straight to wrap the search string to make it a word boundary with \b

ybz12003
Rhodochrosite | Level 12

Thank you.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 608 views
  • 0 likes
  • 2 in conversation