<?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: Filtering Not Correct With Macro Variable in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Filtering-Not-Correct-With-Macro-Variable/m-p/386384#M24899</link>
    <description>&lt;P&gt;Adding extra macro quoting into generated code can cause havoc with SAS's ability to properly parse the generated commands.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Adding single quotes into the macro variable should work fine for the code you posted. Make sure not to add more quotes in the SQL query. &amp;nbsp; You can easily test by just hard coding the macro variable. &amp;nbsp;If it works that way then the issue is with the CALL SYMPUTX() syntax.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let currentyear='2017' ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But perhaps your code was also using that macro variable for other things where the quotes would cause trouble? &amp;nbsp;Like as part of filename or variable name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have found that when working the pass-through code generation it is useful to have a simple %SQUOTE() macro you can use to add single quotes. &amp;nbsp;Check out this one:&amp;nbsp;&lt;A href="https://github.com/sasutils/macros/blob/master/squote.sas&amp;nbsp;" target="_blank"&gt;https://github.com/sasutils/macros/blob/master/squote.sas&amp;nbsp;&lt;/A&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro squote(value);
%if %sysevalf(&amp;amp;sysver &amp;lt; 9.3) %then
%unquote(%str(%')%qsysfunc(tranwrd(%superq(value),%str(%'),''))%str(%'))
;
%else %sysfunc(quote(%superq(value),%str(%'))) ;
%mend squote;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Aug 2017 19:35:08 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-08-08T19:35:08Z</dc:date>
    <item>
      <title>Filtering Not Correct With Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Filtering-Not-Correct-With-Macro-Variable/m-p/386307#M24894</link>
      <description>&lt;P&gt;I have a macro variable defined to filter based on the current year. And when I use the macro variable to filter the year, it does not pull the information (essentially pulls nothing becuase the filter is not seeing any matches). However if I type in the year in filter it works. I have included both sets of code and the column properties of the table to be filtered (point_acct) and the table where the output of what the values of the macro variables are set to. Note, that all the other macro variables you will see defined filter properly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note there is some intervening code to establish the oracle passthrough and tables, but that wasn't germaine to this question and has been left out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code without macro variable:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;execute(create table afc_nbr_join as&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select i.inv_id, i.inv_type_cd, i.repair_cd, i.commod_cd, i.fsc_cd, i.niin, i.noun_nm, i.unit_price_amt, p.afc_nbr&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; from inv i, point_acct p&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; where i.commod_cd=p.commod_cd&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and i.inv_stat_cd='A'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and p.approp_fy_nbr =&amp;nbsp;'2017'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and p.commod_cd not in ('1','2','3')&lt;BR /&gt;union&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select i.inv_id, i.inv_type_cd, i.repair_cd, i.commod_cd, i.fsc_cd, i.niin, i.noun_nm, i.unit_price_amt, p.afc_nbr&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; from inv i, point_acct p&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; where i.commod_cd=p.commod_cd&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and i.inv_stat_cd='A'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;and p.commod_cd&amp;nbsp; in ('1','2','3')) by oracle;&lt;BR /&gt;disconnect from oracle;&lt;BR /&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code with Macro Variables:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DATA _null_;&lt;BR /&gt;&amp;nbsp;YP2DB = INTNX('year',today(),-2,'B');&lt;BR /&gt;&amp;nbsp;YP5DB = INTNX('year',today(),-5,'B');&lt;BR /&gt;&amp;nbsp;CALL SYMPUT('oracle_2YearDate',strip(put(YP2DB,date11.)));&lt;BR /&gt;&amp;nbsp;CALL SYMPUT('oracle_5YearDate',strip(put(YP5DB,date11.)));&lt;BR /&gt;&amp;nbsp;CALL SYMPUTX ('TWOYEARSPRIOR',strip((PUT(YP2DB,year4.))));&lt;BR /&gt;&amp;nbsp;CALL SYMPUTX ('FIVEYEARSPRIOR',strip(PUT(YP5DB,year4.)));&lt;BR /&gt;&amp;nbsp;CALL SYMPUTX ('CURRENTYEAR',strip(PUT(today(),year4.)));&lt;BR /&gt;RUN;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;execute(create table afc_nbr_join as&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select i.inv_id, i.inv_type_cd, i.repair_cd, i.commod_cd, i.fsc_cd, i.niin, i.noun_nm, i.unit_price_amt, p.afc_nbr&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; from inv i, point_acct p&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; where i.commod_cd=p.commod_cd&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and i.inv_stat_cd='A'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and p.approp_fy_nbr = %str(%') &amp;amp;currentyear %str(%')&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and p.commod_cd not in ('1','2','3')&lt;BR /&gt;union&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select i.inv_id, i.inv_type_cd, i.repair_cd, i.commod_cd, i.fsc_cd, i.niin, i.noun_nm, i.unit_price_amt, p.afc_nbr&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; from inv i, point_acct p&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; where i.commod_cd=p.commod_cd&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and i.inv_stat_cd='A'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;and p.commod_cd&amp;nbsp; in ('1','2','3')) by oracle;&lt;BR /&gt;disconnect from oracle;&lt;BR /&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Screen shots attached as word document.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Erin&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV class="nH"&gt;&lt;DIV class="nH"&gt;&lt;DIV class="nH bkL"&gt;&lt;DIV class="no"&gt;&lt;DIV class="nH bkK nn"&gt;&lt;DIV class="nH"&gt;&lt;DIV class="nH"&gt;&lt;DIV class="nH ar4 z"&gt;&lt;DIV&gt;&lt;DIV class="AO"&gt;&lt;DIV class="Tm aeJ"&gt;&lt;DIV class="aeF"&gt;&lt;DIV class="nH"&gt;&lt;DIV class="nH"&gt;&lt;DIV class="nH g"&gt;&lt;TABLE cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 08 Aug 2017 15:43:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Filtering-Not-Correct-With-Macro-Variable/m-p/386307#M24894</guid>
      <dc:creator>ErinKSimmons</dc:creator>
      <dc:date>2017-08-08T15:43:13Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering Not Correct With Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Filtering-Not-Correct-With-Macro-Variable/m-p/386308#M24895</link>
      <description>&lt;P&gt;Looks like you have added spaces inside the quotes. &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;        and p.approp_fy_nbr = %str(%') &amp;amp;currentyear %str(%')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But perhaps the macro quoting added by using %STR() is also confusing SAS? Try removing it also.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;        and p.approp_fy_nbr = %unquote(%str(%')&amp;amp;currentyear.%str(%'))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Why not just add the single quotes into the macro variable?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; CALL SYMPUTX ('CURRENTYEAR',quote(PUT(today(),year4.),"'"));
...
        and p.approp_fy_nbr = &amp;amp;currentyear&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 15:59:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Filtering-Not-Correct-With-Macro-Variable/m-p/386308#M24895</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-08-08T15:59:16Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering Not Correct With Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Filtering-Not-Correct-With-Macro-Variable/m-p/386379#M24898</link>
      <description>&lt;P&gt;Tom-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the record, the first option with the %unquote worked, but the second with putting the quotes in the symputx did not. (I also tried running it without the %str() altogether and that also didn't work, so I am not sure why but doing the Oracle passthrough in this case needed both the %unquote(%str(%') &amp;amp;currentyear %str(%'))).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Erin&lt;/P&gt;&lt;DIV class="lia-page"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Tue, 08 Aug 2017 19:24:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Filtering-Not-Correct-With-Macro-Variable/m-p/386379#M24898</guid>
      <dc:creator>ErinKSimmons</dc:creator>
      <dc:date>2017-08-08T19:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering Not Correct With Macro Variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Filtering-Not-Correct-With-Macro-Variable/m-p/386384#M24899</link>
      <description>&lt;P&gt;Adding extra macro quoting into generated code can cause havoc with SAS's ability to properly parse the generated commands.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Adding single quotes into the macro variable should work fine for the code you posted. Make sure not to add more quotes in the SQL query. &amp;nbsp; You can easily test by just hard coding the macro variable. &amp;nbsp;If it works that way then the issue is with the CALL SYMPUTX() syntax.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let currentyear='2017' ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But perhaps your code was also using that macro variable for other things where the quotes would cause trouble? &amp;nbsp;Like as part of filename or variable name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have found that when working the pass-through code generation it is useful to have a simple %SQUOTE() macro you can use to add single quotes. &amp;nbsp;Check out this one:&amp;nbsp;&lt;A href="https://github.com/sasutils/macros/blob/master/squote.sas&amp;nbsp;" target="_blank"&gt;https://github.com/sasutils/macros/blob/master/squote.sas&amp;nbsp;&lt;/A&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro squote(value);
%if %sysevalf(&amp;amp;sysver &amp;lt; 9.3) %then
%unquote(%str(%')%qsysfunc(tranwrd(%superq(value),%str(%'),''))%str(%'))
;
%else %sysfunc(quote(%superq(value),%str(%'))) ;
%mend squote;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2017 19:35:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Filtering-Not-Correct-With-Macro-Variable/m-p/386384#M24899</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-08-08T19:35:08Z</dc:date>
    </item>
  </channel>
</rss>

