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!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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