10-19-2017 02:46 PM - edited 10-19-2017 02:48 PM
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.
Below is the error:
NOTE: Line generated by the macro variable "TF_CONDITION".
30 UPCASE(tools) IN ("POWER TOOL1","POWER TOOL2","POWER TOOL3")
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.
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.
10-19-2017 03:12 PM
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.
10-19-2017 03:29 PM
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") ;
Need further help from the community? Please ask a new question.