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.
%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 |
%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 |
What is the '\b' for? Why need to one at the front and one at the end?
\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
Thank you.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.