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

I am trying to build Condition using some macro variables. tf_condition is the macro variable that holds the condition. Below is from the log.

 

tf_condition: UPCASE(tools) IN ("POWER TOOL1","POWER TOOL2","POWER TOOL3")

 

Then I use in a DATA STEP to filter the data.

 

DATA tools;

   SET tools_all;

  WHERE &tf_condition.;

RUN;

 

Below is the error:

 

WHERE &tf_condition;
NOTE: Line generated by the macro variable "TF_CONDITION".
30 UPCASE(tools) IN ("POWER TOOL1","POWER TOOL2","POWER TOOL3")
                                    _  _
                                   22 76
ERROR: Syntax error while parsing WHERE clause.
ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant, a datetime constant,
a missing value, -.

ERROR 76-322: Syntax error, statement will be ignored.

31 RUN;

 

If I ran the DATA step substituting value of tf_condition, then it runs fine.

 

I don't understand where is the problem.  Please help.

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Try 

 

WHERE %unquote(&tf_condition);
--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Try 

 

WHERE %unquote(&tf_condition);
--
Paige Miller
KrisNori
Obsidian | Level 7

Thank You. It works. Just curious, what's the prob here ?

PaigeMiller
Diamond | Level 26

What is the problem?

 

Well, I can't really explain it, all I know is that when I see this error, %UNQUOTE fixes it. Perhaps Mr. @Astounding can explain it, he wrote a book about this stuff.

--
Paige Miller
Astounding
PROC Star

The problem lies in the creation of the macro variable.  It must have been created using macro quoting functions as part of the code, which means that there are extraneous characters inserted into the value of the macro variable.  Usually, the software figures out what to do, which means that macro language removes those extraneous characters before passing the SAS statements to the SAS language processor.  But sometimes macro language gets it wrong and doesn't figure it out in time to correctly parse the characters within the macro variable.  Most notorious for having this flaw:  PROC SQL, and WHERE statements.  If you were to use this plain vanilla assignment (with no macro quoting functions), there should be no problem with referring to the macro variable:

 

%let tf_condition = UPCASE(tools) IN ("POWER TOOL1","POWER TOOL2","POWER TOOL3") ;

 

DATA tools;

   SET tools_all;

  WHERE &tf_condition.;

RUN;

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