DATA Step, Macro, Functions and more

Need help with macro variable not resolving correctly inside of a macro.

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 82
Accepted Solution

Need help with macro variable not resolving correctly inside of a macro.

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')

 

 


Accepted Solutions
Solution
‎03-21-2016 10:25 AM
Super User
Posts: 5,497

Re: Need help with macro variable not resolving correctly inside of a macro.

Posted in reply to ncsthbell

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


All Replies
Super Contributor
Posts: 308

Re: Need help with macro variable not resolving correctly inside of a macro.

Posted in reply to ncsthbell

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

Solution
‎03-21-2016 10:25 AM
Super User
Posts: 5,497

Re: Need help with macro variable not resolving correctly inside of a macro.

Posted in reply to ncsthbell

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.

 

 

Frequent Contributor
Posts: 82

Re: Need help with macro variable not resolving correctly inside of a macro.

Posted in reply to Astounding

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

 

Thanks a bunch!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 251 views
  • 0 likes
  • 3 in conversation