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