<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: macro variable in a DATA Step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-a-DATA-Step/m-p/405687#M98724</link>
    <description>&lt;P&gt;Thank You. It&amp;nbsp;works. Just curious, what's the prob here ?&lt;/P&gt;</description>
    <pubDate>Thu, 19 Oct 2017 19:09:25 GMT</pubDate>
    <dc:creator>KrisNori</dc:creator>
    <dc:date>2017-10-19T19:09:25Z</dc:date>
    <item>
      <title>macro variable in a DATA Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-a-DATA-Step/m-p/405681#M98722</link>
      <description>&lt;P&gt;I am trying to build&amp;nbsp;Condition using some macro variables.&amp;nbsp;tf_condition is the macro variable that holds the condition. Below is from the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;tf_condition: UPCASE(tools) IN ("POWER TOOL1","POWER TOOL2","POWER TOOL3")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I use in a DATA STEP to filter the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA tools;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;SET tools_all;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; WHERE &amp;amp;tf_condition.;&lt;/P&gt;
&lt;P&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is the error:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WHERE &amp;amp;tf_condition;&lt;BR /&gt;NOTE: Line generated by the macro variable "TF_CONDITION".&lt;BR /&gt;30 &lt;SPAN&gt;UPCASE(&lt;/SPAN&gt;&lt;SPAN&gt;tools&lt;/SPAN&gt;&lt;SPAN&gt;) IN ("&lt;/SPAN&gt;&lt;SPAN&gt;POWER TOOL1&lt;/SPAN&gt;&lt;SPAN&gt;","POWER&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;TOOL2&lt;/SPAN&gt;&lt;SPAN&gt;","POWER TOOL3")&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _&amp;nbsp; _&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;22 76&lt;BR /&gt;&lt;FONT color="#FF6600"&gt;&lt;STRONG&gt;ERROR: Syntax error while parsing WHERE clause.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF6600"&gt;&lt;STRONG&gt;ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant, a datetime constant, &lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF6600"&gt;&lt;STRONG&gt; a missing value, -.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF6600"&gt;&lt;STRONG&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;31 RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I ran the DATA step substituting value of tf_condition, then it runs fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't understand where is the problem.&amp;nbsp; Please help.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 18:48:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-a-DATA-Step/m-p/405681#M98722</guid>
      <dc:creator>KrisNori</dc:creator>
      <dc:date>2017-10-19T18:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable in a DATA Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-a-DATA-Step/m-p/405684#M98723</link>
      <description>&lt;P&gt;Try&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;WHERE %unquote(&amp;amp;tf_condition);&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Oct 2017 19:03:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-a-DATA-Step/m-p/405684#M98723</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-10-19T19:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable in a DATA Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-a-DATA-Step/m-p/405687#M98724</link>
      <description>&lt;P&gt;Thank You. It&amp;nbsp;works. Just curious, what's the prob here ?&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 19:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-a-DATA-Step/m-p/405687#M98724</guid>
      <dc:creator>KrisNori</dc:creator>
      <dc:date>2017-10-19T19:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable in a DATA Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-a-DATA-Step/m-p/405689#M98725</link>
      <description>&lt;P&gt;What is the problem?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Well, I can't really explain it, all I know is that when I see this error, %UNQUOTE fixes it. Perhaps Mr.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;can explain it, he wrote a book about this stuff.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 19:12:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-a-DATA-Step/m-p/405689#M98725</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-10-19T19:12:06Z</dc:date>
    </item>
    <item>
      <title>Re: macro variable in a DATA Step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-a-DATA-Step/m-p/405698#M98728</link>
      <description>&lt;P&gt;The problem lies in the creation of the macro variable.&amp;nbsp; 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.&amp;nbsp; 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.&amp;nbsp; But sometimes macro language gets it wrong and doesn't figure it out in time to correctly parse the characters within the macro variable.&amp;nbsp; Most notorious for having this flaw:&amp;nbsp; PROC SQL, and WHERE statements.&amp;nbsp; 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:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let tf_condition = UPCASE(tools) IN ("POWER TOOL1","POWER TOOL2","POWER TOOL3") ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA tools;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;SET tools_all;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; WHERE &amp;amp;tf_condition.;&lt;/P&gt;
&lt;P&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 19:29:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-variable-in-a-DATA-Step/m-p/405698#M98728</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-10-19T19:29:34Z</dc:date>
    </item>
  </channel>
</rss>

