<?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 Syntax Error: Quotes in Macro Parameter Generated by EG Prompt in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Syntax-Error-Quotes-in-Macro-Parameter-Generated-by-EG-Prompt/m-p/394370#M25407</link>
    <description>&lt;P&gt;On Enterprise Guide 7.1, I encountered a syntax error related to quotes in a macro parameter. An abbreviated version of the code in question follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table testtable1 as
select * 
from in1.eligibility
where 201501&amp;lt;=monthid&amp;lt;=201706 
&amp;amp;whereavars.;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I then created a user prompt for&amp;nbsp;&lt;STRONG&gt;whereavars&lt;/STRONG&gt; and entered the following text:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;and avar4="STAR"&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This produced a syntax error when I tried to run the SQL query above.&lt;/P&gt;&lt;P&gt;I know the syntax error is related to the quotes because I changed the prompt text to&amp;nbsp;&lt;STRONG&gt;and 1&amp;nbsp;&lt;/STRONG&gt;and the SQL query ran without issue.&amp;nbsp;I tried single quotes instead of double and got the same result.&lt;/P&gt;&lt;P&gt;I even tried creating the macro variable in the program instead of the prompt. This query worked, too. So this has something to do with the quotes and the prompt.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;</description>
    <pubDate>Fri, 08 Sep 2017 22:35:21 GMT</pubDate>
    <dc:creator>adkilmer</dc:creator>
    <dc:date>2017-09-08T22:35:21Z</dc:date>
    <item>
      <title>Syntax Error: Quotes in Macro Parameter Generated by EG Prompt</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Syntax-Error-Quotes-in-Macro-Parameter-Generated-by-EG-Prompt/m-p/394370#M25407</link>
      <description>&lt;P&gt;On Enterprise Guide 7.1, I encountered a syntax error related to quotes in a macro parameter. An abbreviated version of the code in question follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table testtable1 as
select * 
from in1.eligibility
where 201501&amp;lt;=monthid&amp;lt;=201706 
&amp;amp;whereavars.;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I then created a user prompt for&amp;nbsp;&lt;STRONG&gt;whereavars&lt;/STRONG&gt; and entered the following text:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;and avar4="STAR"&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This produced a syntax error when I tried to run the SQL query above.&lt;/P&gt;&lt;P&gt;I know the syntax error is related to the quotes because I changed the prompt text to&amp;nbsp;&lt;STRONG&gt;and 1&amp;nbsp;&lt;/STRONG&gt;and the SQL query ran without issue.&amp;nbsp;I tried single quotes instead of double and got the same result.&lt;/P&gt;&lt;P&gt;I even tried creating the macro variable in the program instead of the prompt. This query worked, too. So this has something to do with the quotes and the prompt.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2017 22:35:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Syntax-Error-Quotes-in-Macro-Parameter-Generated-by-EG-Prompt/m-p/394370#M25407</guid>
      <dc:creator>adkilmer</dc:creator>
      <dc:date>2017-09-08T22:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax Error: Quotes in Macro Parameter Generated by EG Prompt</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Syntax-Error-Quotes-in-Macro-Parameter-Generated-by-EG-Prompt/m-p/394373#M25408</link>
      <description>&lt;P&gt;What is the error? Please paste the code with the error from the log into a code box using the forum {i} menu icon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing to do is to run the code with&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options mprint;&lt;/P&gt;
&lt;P&gt;Then the code generated by the macro variable should show in the log. it may appear a bit differently than you think.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2017 23:00:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Syntax-Error-Quotes-in-Macro-Parameter-Generated-by-EG-Prompt/m-p/394373#M25408</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-09-08T23:00:55Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax Error: Quotes in Macro Parameter Generated by EG Prompt</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Syntax-Error-Quotes-in-Macro-Parameter-Generated-by-EG-Prompt/m-p/394432#M25409</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/163777"&gt;@adkilmer&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;If you investigate your SAS log you'll find something like:&lt;/P&gt;
&lt;PRE&gt;%LET WHEREAVARS = and avar4=%nrstr(%")STAR(%");&lt;/PRE&gt;
&lt;P&gt;Use an %unquote() function as below and things will work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table testtable1 as
    select * 
    from in1.eligibility
    where 201501&amp;lt;=monthid&amp;lt;=201706 
        %unquote(&amp;amp;whereavars.);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2017 12:26:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Syntax-Error-Quotes-in-Macro-Parameter-Generated-by-EG-Prompt/m-p/394432#M25409</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-09-09T12:26:42Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax Error: Quotes in Macro Parameter Generated by EG Prompt</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Syntax-Error-Quotes-in-Macro-Parameter-Generated-by-EG-Prompt/m-p/394434#M25410</link>
      <description>&lt;P&gt;No ideas, just bafflement!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can reproduce your situation exactly. I'm evenly divided between whether it's a bug, or some arcane rule in macro variable substitution that I don't know.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given that a bug is a possibility, if you don't get an answer on this communitiy in a reasonable amount of time, I would have no qualms about submitting this to SAS tech. support. If&amp;nbsp; you've never done it before, don't be apprehensive, they're a great group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To test on my machine, I modified your example a bit. Try this out in your environment, and if it fails successfully (hah!) for you, you can send it to tech support as they'll be able to try it right out of the box.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And for heaven's sake report back. This is driving me nuts!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
create table testtable1 as
select * 
from sashelp.class
where 13&amp;lt;=age&amp;lt;=14
&amp;amp;whereavars.;
quit;
/* Set prompt to and name = "Alice" */&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Sep 2017 12:37:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Syntax-Error-Quotes-in-Macro-Parameter-Generated-by-EG-Prompt/m-p/394434#M25410</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2017-09-09T12:37:06Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax Error: Quotes in Macro Parameter Generated by EG Prompt</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Syntax-Error-Quotes-in-Macro-Parameter-Generated-by-EG-Prompt/m-p/394436#M25411</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15142"&gt;@TomKari&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;See my post. The prompt adds macro quoting for the the double quotes. An %unquote() resolves the issue.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2017 12:48:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Syntax-Error-Quotes-in-Macro-Parameter-Generated-by-EG-Prompt/m-p/394436#M25411</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-09-09T12:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax Error: Quotes in Macro Parameter Generated by EG Prompt</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Syntax-Error-Quotes-in-Macro-Parameter-Generated-by-EG-Prompt/m-p/394442#M25413</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;Very cool! Thanks. I'm far from an expert on macro quoting, so I was hoping someone more knowledgeable than me would come to the rescue. Now this can quit bugging me, and I'll know for the future!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2017 13:26:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Syntax-Error-Quotes-in-Macro-Parameter-Generated-by-EG-Prompt/m-p/394442#M25413</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2017-09-09T13:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: Syntax Error: Quotes in Macro Parameter Generated by EG Prompt</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Syntax-Error-Quotes-in-Macro-Parameter-Generated-by-EG-Prompt/m-p/394443#M25414</link>
      <description>&lt;P&gt;SAS Enterpise Guide and SAS/Studio normally use %BQUOTE() when creating the macro variables. &amp;nbsp;There should be options you can change that will show the generated code in the SAS log.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let where = %bquote(and name='Alfred');
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It is this macro quoting that is causing your problem. You can&amp;nbsp;use %unquote() to remove the macro quoting.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table test1 as
  select * 
  from sashelp.class
  where 1=1 %unquote(&amp;amp;where)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Without removing the macro quoting the SAS parser is not seeing the quotes as indicating a string literal and so it causes syntax errors.&lt;/P&gt;
&lt;PRE&gt;90    proc sql ;
91    create table test2 as
92      select *
93      from sashelp.class
94      where 1=1 &amp;amp;where
95    ;
NOTE: Line generated by the macro variable "WHERE".
1      and name='Alfred'
                -
                22
                 -
                 200
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant,
              a datetime constant, a missing value, (, *, +, -, ALL, ANY, BTRIM, CALCULATED, CASE, INPUT,
              PUT, SELECT, SOME, SUBSTRING, TRANSLATE, USER.

ERROR 200-322: The symbol is not recognized and will be ignored.

96    quit;
&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Sep 2017 14:07:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Syntax-Error-Quotes-in-Macro-Parameter-Generated-by-EG-Prompt/m-p/394443#M25414</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-09T14:07:59Z</dc:date>
    </item>
  </channel>
</rss>

