I want to insert the two-character state abbreviation for a missing value. The state can change based on the data set I'm using. If I try pass through a macro variable, I get a value of '&' rather than 'WI'.
%macro get_State(st);
data xxx; set yyy;
if State = "" then State = '&st';
run;
%get_State(WI)Is there any way I can get the macro variable st to be evaluated as a character string?
Macro variables do not resolve inside single quotes.
Use
%macro get_State(st);
data xxx; set yyy;
if State = "" then State = "&st";
run;
If you have a reliable value for ZIPcode you might use the ZIPSTATE function and skip this whole macro.
data xxx; set yyy;
if State = "" then State = Zipstate(zipcode);
run;
This would correct all the missing if you have a zipcode value. Just a thought. Otherwise you may have some other issues if you need to change more than one state value.
Macro variables do not resolve inside single quotes.
Use
%macro get_State(st);
data xxx; set yyy;
if State = "" then State = "&st";
run;
If you have a reliable value for ZIPcode you might use the ZIPSTATE function and skip this whole macro.
data xxx; set yyy;
if State = "" then State = Zipstate(zipcode);
run;
This would correct all the missing if you have a zipcode value. Just a thought. Otherwise you may have some other issues if you need to change more than one state value.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.