BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DocMartin
Quartz | Level 8

 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?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

1 REPLY 1
ballardw
Super User

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 792 views
  • 0 likes
  • 2 in conversation