<?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 Macro language tokenization bug: &amp;quot;%%foo&amp;quot; will not trigger macro processor in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-language-tokenization-bug-quot-foo-quot-will-not-trigger/m-p/895601#M353858</link>
    <description>&lt;P&gt;In answering another question,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;&amp;nbsp;pointed out that code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"%%foo"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will not trigger the macro processor to execute the macro FOO.&amp;nbsp;&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/warning-in-macro/m-p/895236/highlight/true#M353679" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/warning-in-macro/m-p/895236/highlight/true#M353679&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This was a surprise to me, and I think it is likely a word scanner / tokenization bug.&amp;nbsp; I'm not aware of any documented feature of the macro language that would explain this behavior.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In testing more, found some interesting results.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The issue only seems to happen when there are an even number of consecutive macro triggers, i.e. %% or &amp;amp;% that appear inside of double quotes or parentheses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would expect all examples below to trigger the macro processor to execute the macro FOO.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basic example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %%Foo ;    *Does trigger macro processor ;
%put "%%Foo" ;   *Does NOT trigger macro processor ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It's not a %PUT statement issue.&amp;nbsp; And it's not that %% is somehow resolving to %:&lt;/P&gt;
&lt;PRE&gt;1    data want;
2      x="%%Foo" ;  *Does NOT trigger macro processor ;
3      put x= ;
4    run ;

x=%%Foo
NOTE: The data set WORK.WANT has 1 observations and 1 variables.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An odd number of % signs triggers macro processor, even does not:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put "%Foo" ;    *Does trigger macro processor ;
%put "%%Foo" ;   *Does NOT trigger macro processor ;
%put "%%%Foo" ;  *Does trigger macro processor ;
%put "%%%%Foo" ; *Does NOT trigger macro processor ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Parentheses can also cause the issue:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %length(%foo) ;   *Does trigger macro processor ;
%put %length(%%foo) ;  *Does NOT trigger macro processor ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;An ampersand followed by one or more percent signs seems to have the same effect:&lt;/P&gt;
&lt;PRE&gt;%put &amp;amp;%Foo ;     *Does trigger macro processor ;
%put "&amp;amp;%Foo" ;   *Does NOT trigger macro processor ;

%put "%Foo" ;    *Does trigger macro processor ;
%put "&amp;amp;%Foo" ;   *Does NOT trigger macro processor ;
%put "&amp;amp;%%Foo" ;  *Does trigger macro processor ;
%put "&amp;amp;%%%Foo" ; *Does NOT trigger macro processor ;

data want;
  x="&amp;amp;%Foo" ;  *Does NOT trigger macro processor ;
  put x= ;
run ;

%put %length(&amp;amp;%foo) ;  *Does NOT trigger macro processor ;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I submitted the issue to tech support (&lt;SPAN&gt;CS0017798).&amp;nbsp; They confirmed the behavior, and have escalated to R&amp;amp;D for an explanation.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 24 Sep 2023 19:31:59 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2023-09-24T19:31:59Z</dc:date>
    <item>
      <title>Macro language tokenization bug: "%%foo" will not trigger macro processor</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-language-tokenization-bug-quot-foo-quot-will-not-trigger/m-p/895601#M353858</link>
      <description>&lt;P&gt;In answering another question,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;&amp;nbsp;pointed out that code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"%%foo"&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will not trigger the macro processor to execute the macro FOO.&amp;nbsp;&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/warning-in-macro/m-p/895236/highlight/true#M353679" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/warning-in-macro/m-p/895236/highlight/true#M353679&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This was a surprise to me, and I think it is likely a word scanner / tokenization bug.&amp;nbsp; I'm not aware of any documented feature of the macro language that would explain this behavior.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In testing more, found some interesting results.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The issue only seems to happen when there are an even number of consecutive macro triggers, i.e. %% or &amp;amp;% that appear inside of double quotes or parentheses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would expect all examples below to trigger the macro processor to execute the macro FOO.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basic example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %%Foo ;    *Does trigger macro processor ;
%put "%%Foo" ;   *Does NOT trigger macro processor ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It's not a %PUT statement issue.&amp;nbsp; And it's not that %% is somehow resolving to %:&lt;/P&gt;
&lt;PRE&gt;1    data want;
2      x="%%Foo" ;  *Does NOT trigger macro processor ;
3      put x= ;
4    run ;

x=%%Foo
NOTE: The data set WORK.WANT has 1 observations and 1 variables.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An odd number of % signs triggers macro processor, even does not:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put "%Foo" ;    *Does trigger macro processor ;
%put "%%Foo" ;   *Does NOT trigger macro processor ;
%put "%%%Foo" ;  *Does trigger macro processor ;
%put "%%%%Foo" ; *Does NOT trigger macro processor ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Parentheses can also cause the issue:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %length(%foo) ;   *Does trigger macro processor ;
%put %length(%%foo) ;  *Does NOT trigger macro processor ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;An ampersand followed by one or more percent signs seems to have the same effect:&lt;/P&gt;
&lt;PRE&gt;%put &amp;amp;%Foo ;     *Does trigger macro processor ;
%put "&amp;amp;%Foo" ;   *Does NOT trigger macro processor ;

%put "%Foo" ;    *Does trigger macro processor ;
%put "&amp;amp;%Foo" ;   *Does NOT trigger macro processor ;
%put "&amp;amp;%%Foo" ;  *Does trigger macro processor ;
%put "&amp;amp;%%%Foo" ; *Does NOT trigger macro processor ;

data want;
  x="&amp;amp;%Foo" ;  *Does NOT trigger macro processor ;
  put x= ;
run ;

%put %length(&amp;amp;%foo) ;  *Does NOT trigger macro processor ;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I submitted the issue to tech support (&lt;SPAN&gt;CS0017798).&amp;nbsp; They confirmed the behavior, and have escalated to R&amp;amp;D for an explanation.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Sep 2023 19:31:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-language-tokenization-bug-quot-foo-quot-will-not-trigger/m-p/895601#M353858</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-09-24T19:31:59Z</dc:date>
    </item>
    <item>
      <title>Re: Macro language tokenization bug: "%%foo" will not trigger macro processor</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-language-tokenization-bug-quot-foo-quot-will-not-trigger/m-p/897645#M354735</link>
      <description>&lt;P&gt;I heard back from Tech Support.&amp;nbsp; They didn't provide any interesting insights or explanations, but they did confirm that this is a bug, and said they will be documenting it with a new problem note.&amp;nbsp; I asked them to share the URL after the note is published so that I can link to it from here.&amp;nbsp; But for now, I'll mark this as the accepted answer to close this out.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2023 20:27:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-language-tokenization-bug-quot-foo-quot-will-not-trigger/m-p/897645#M354735</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-10-06T20:27:54Z</dc:date>
    </item>
  </channel>
</rss>

