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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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