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!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.