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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.