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

I am trying to assign the variable of 'NEW_STATE' to the prompt value the user has entered and wrap the value in quotes to use in building my where clause.   When I try to run it, I get no results because the assignment of the variable 'NEW_STATE' is not correct.  Here is my code:

%macro BuildWhereClause;
   %global where_clause;
   %let where_clause = ;

/* check prompt STATE for user entered values */
  %if %length(&STATE) > 0 %then %do ;       
%let NEW_STATE = '&STATE'; %let where_clause = &where_clause AND UPCASE(t1.STATE) = UPCASE(&NEW_STATE); %end; /* display values of demograpic prompts */ %put &STATE; %put &NEW_STATE; %put ******** where_clause is = &where_clause; %mend; %BuildWhereClause; Value of the variables from the %put statements: NC -- value of &STATE, user entered prompt. '&STATE' -- value of &NEW_STATE I need this to have the value of UPCASE('NC') ******** where_clause is = AND UPCASE(t1.STATE) = UPCASE('&STATE') This needs to be UPCASE('NC')

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Single quotes suppress all macro activity.  Switch to double quotes:

 

%let NEW_STATE = "&STATE";

 

Also note, this works as long as &STATE contains just a single state code.  If it could contain multiple state codes, you will need to quote each one individually.

 

 

View solution in original post

3 REPLIES 3
Loko
Barite | Level 11

How the user enter the values? do you have a SAS Stored Process?

Astounding
PROC Star

Single quotes suppress all macro activity.  Switch to double quotes:

 

%let NEW_STATE = "&STATE";

 

Also note, this works as long as &STATE contains just a single state code.  If it could contain multiple state codes, you will need to quote each one individually.

 

 

ncsthbell
Quartz | Level 8

Worked perfectly!!   I did not realize that the single quotes would suppress the macro activity.  Learn something new everyday with SAS!

 

Thanks a bunch!

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
  • 3 replies
  • 1731 views
  • 0 likes
  • 3 in conversation