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')
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.
How the user enter the values? do you have a SAS Stored Process?
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.
Worked perfectly!! I did not realize that the single quotes would suppress the macro activity. Learn something new everyday with SAS!
Thanks a bunch!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for 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.