Hello,
I created a macro list below.
proc sql noprint;
select trim(State_Abbr) into : Jurisdiction_list separated by '|' from States;
quit;
%put &Jurisdiction_list;
and the result is shown below.
AL|AK|AZ|AR|CA|CO|CT|DE|FL|GA
Then I run a data step in PRXMATCH, I found the &Jurisdiction_list. was NOT able to recognize. Any idea why?
data want;
SET test;
if prxmatch ('/&Jurisdiction_list./i',ID) then TempID=ID;
run;
Did you miss to enclose the string literal in double quotes " "
prxmatch ("/&Jurisdiction_list./i",ID)
But when I hardcode for that list, it worked. I can't figure out where went wrong from the above codes.
data want;
SET test;
if prxmatch ('/AL|AK|AZ|AR|CA/i',id) then TempID=id;
run;
use double quotes to enclose your macro variable.
24 25 GOPTIONS ACCESSIBLE; 26 %Let Jurisdiction_list=%str(AL|AK|AZ|AR|CA|CO|CT|DE|FL|GA); 27 28 data _null_; 29 /* SET test;*/ 30 ID='AK'; 31 32 if prxmatch ("/&Jurisdiction_list./i",ID) then TempID=ID; 33 34 put TempID=; 35 run; TempID=AK
Hi @ybz12003 ,
The use of single quotes prevents the resolution of the macrovariable, so you need to use double quotes to avoid this.
if prxmatch ("/AL|AK|AZ|AR|CA/I",id) then TempID=id;
All the best,
Did you miss to enclose the string literal in double quotes " "
prxmatch ("/&Jurisdiction_list./i",ID)
Thank you so much. I didn't know it need to use double quote for the macro list.
Calling all data scientists and open-source enthusiasts! Want to solve real problems that impact your company or the world? Register to hack by August 31st!
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.