<?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 resolution bug with % sign in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-bug-with-sign/m-p/891497#M352191</link>
    <description>&lt;P&gt;I think it is more related to the bare %.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1    options symbolgen ;
2    %let x=%nrstr(%%) ;
3    %let y=B ;
4    %put &amp;amp;x A&amp;amp;y ;
SYMBOLGEN:  Macro variable X resolves to %
SYMBOLGEN:  Some characters in the above value which were subject to macro
            quoting have been unquoted for printing.
SYMBOLGEN:  Macro variable Y resolves to B
% AB
&lt;/PRE&gt;
&lt;P&gt;Note that %nrstr(%); is one of those things that creates and unstable macro situation and you only see the error about an unfound closing parentheses when shutting down SAS, at least with a relatively "clean" session just testing this code. Use of %str(%%) does the same behavior as observed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Aug 2023 14:16:23 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-08-29T14:16:23Z</dc:date>
    <item>
      <title>Macro variable resolution bug with % sign</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-bug-with-sign/m-p/891484#M352185</link>
      <description>&lt;P&gt;Woke up this morning to an interesting post on stack overflow reporting a macro resolution bug.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/76997015/what-happend-when-a-macro-variable-with-percent-symbol-as-its-value-in-put-stat" target="_blank"&gt;https://stackoverflow.com/questions/76997015/what-happend-when-a-macro-variable-with-percent-symbol-as-its-value-in-put-stat&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Coding:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options symbolgen ;
%let x=% ;
%let y=B ;
%put &amp;amp;x A&amp;amp;y ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;should return % AB but it returns % AB AB and symbolgen even shows that Y resolves twice:&lt;/P&gt;
&lt;PRE&gt;1    options symbolgen ;
2
3    %let x=% ;
4    %let y=B ;
5
6    %put &amp;amp;x A&amp;amp;y ;
SYMBOLGEN:  Macro variable X resolves to %
SYMBOLGEN:  Macro variable Y resolves to B
SYMBOLGEN:  Macro variable Y resolves to B
% AB  AB&lt;/PRE&gt;
&lt;P&gt;I thought "that's a weird bug in the %PUT statement" and then got more concerned when I saw that it really is a macro resolution bug, e.g.:&lt;/P&gt;
&lt;PRE&gt;8    data _null_ ;
9     x ="&amp;amp;x A&amp;amp;y" ;
SYMBOLGEN:  Macro variable X resolves to %
SYMBOLGEN:  Macro variable Y resolves to B
SYMBOLGEN:  Macro variable Y resolves to B
10    put x= ;
11   run ;
x=% AB AB&lt;/PRE&gt;
&lt;P&gt;Anyone seen this before or better yet, have an explanation for how this could be tripping up the macro processor?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2023 13:22:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-bug-with-sign/m-p/891484#M352185</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-08-29T13:22:53Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable resolution bug with % sign</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-bug-with-sign/m-p/891494#M352189</link>
      <description>&lt;P&gt;You can try raising a SAS support ticket, but since this behavior has existed since at least SAS 9.2 I am not sure they will fix it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems be triggered only when SAS is confused about whether to treat that as one token or two.&amp;nbsp; For example if you replace the space between the two with a + or another character that would start a new token the double generation does not happen.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also avoid it be adding macro quoting the the macro variable that has the bare % in it.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2023 14:11:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-bug-with-sign/m-p/891494#M352189</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-29T14:11:57Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable resolution bug with % sign</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-bug-with-sign/m-p/891497#M352191</link>
      <description>&lt;P&gt;I think it is more related to the bare %.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1    options symbolgen ;
2    %let x=%nrstr(%%) ;
3    %let y=B ;
4    %put &amp;amp;x A&amp;amp;y ;
SYMBOLGEN:  Macro variable X resolves to %
SYMBOLGEN:  Some characters in the above value which were subject to macro
            quoting have been unquoted for printing.
SYMBOLGEN:  Macro variable Y resolves to B
% AB
&lt;/PRE&gt;
&lt;P&gt;Note that %nrstr(%); is one of those things that creates and unstable macro situation and you only see the error about an unfound closing parentheses when shutting down SAS, at least with a relatively "clean" session just testing this code. Use of %str(%%) does the same behavior as observed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2023 14:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-bug-with-sign/m-p/891497#M352191</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-29T14:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable resolution bug with % sign</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-bug-with-sign/m-p/891502#M352193</link>
      <description>&lt;P&gt;%SUPERQ() seems to protect against it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;34   %let x=%;
35   %let y=YSTRING;
36   %put No quoting &amp;amp;x A&amp;amp;y;
No quoting % AYSTRING  AYSTRING
37   %let x=%superq(x);
38   %put SUPERQ &amp;amp;x A&amp;amp;y;
SUPERQ % AYSTRING

&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Aug 2023 14:27:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-bug-with-sign/m-p/891502#M352193</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-29T14:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable resolution bug with % sign</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-bug-with-sign/m-p/891510#M352195</link>
      <description>&lt;P&gt;Agree it's the bare % that is somehow leading to the problem.&amp;nbsp; Even adding trailing spaces to the value in the macro var doesn't prevent the problem:&lt;/P&gt;
&lt;PRE&gt;124  data _null_ ;
125    call symput("x","Foo %  ") ;
126    call symput("y","B") ;
127  run ;


SYMBOLGEN:  Macro variable X resolves to Foo %
128
129  %put &amp;gt;&amp;gt;&amp;amp;x&amp;lt;&amp;lt; ;
&amp;gt;&amp;gt;Foo %  &amp;lt;&amp;lt;
130  %put &amp;amp;x A&amp;amp;y ;
SYMBOLGEN:  Macro variable X resolves to Foo %
SYMBOLGEN:  Macro variable Y resolves to B
SYMBOLGEN:  Macro variable Y resolves to B
Foo %     AB  AB
&lt;/PRE&gt;
&lt;P&gt;Agree it's not likely to be fixed.&amp;nbsp; But still curious about what could cause this behavior.&amp;nbsp; Even with various macro resolution problems, I don't think I've ever seen the macro processor return too much text.&amp;nbsp; I guess maybe it's a word scanner bug.&amp;nbsp; Where the word scanner sends &amp;amp;y off to the macro processor to be resolved, then builds the token AB, then for some reason does it a second time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2023 14:41:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-bug-with-sign/m-p/891510#M352195</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-08-29T14:41:17Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable resolution bug with % sign</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-bug-with-sign/m-p/891536#M352197</link>
      <description>&lt;P&gt;Different types of macro quoting get stored differently into the macro variables.&lt;/P&gt;
&lt;PRE&gt;135  %let x1=%;
136  %let x2=%superq(x1);
137  %let x3=%bquote(&amp;amp;x1);
138  %let x4=%quote(&amp;amp;x2);
139  %let x5=%nrstr(%%);
140  %let x6=%str(%%);
141
142  data test;
143    set sashelp.vmacro;
144    where name=:'X';
145    len=length(value);
146    value2 = putc(value,cats('$hex',2*len,'.'));
147    value=symget(name);
148    put name= len= value=  value2=;
149
150  run;

name=X1 len=1 value=% value2=25
name=X2 len=3 value=% value2=061008
name=X3 len=3 value=% value2=042508
name=X4 len=5 value=% value2=0306100808
name=X5 len=3 value=% value2=011002
name=X6 len=3 value=% value2=012502
NOTE: There were 6 observations read from the data set SASHELP.VMACRO.
      WHERE name=:'X';
NOTE: The data set WORK.TEST has 6 observations and 6 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 second
&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Aug 2023 14:49:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-bug-with-sign/m-p/891536#M352197</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-29T14:49:50Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable resolution bug with % sign</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-bug-with-sign/m-p/891599#M352211</link>
      <description>&lt;P&gt;Came back to this at the end of the day and stumbled across an oddity.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I thought maybe if I used a number instead of A, problem wouldn't happen, because %1 cannot be a macro call so I thought it might tokenize properly.&amp;nbsp; I tried:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x=% ;
%let y=B ;
%put &amp;amp;x 1&amp;amp;y ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And it did repeat. So that theory was wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I noticed that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x=% ;
%let y=B ;
%put &amp;amp;x 1FOO&amp;amp;y ; *does not repeat! ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;does not repeat.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then I noticed that if the characters before &amp;amp;y are a valid hex number, it will repeat.&amp;nbsp; But if they start with a digit but the string prefix string is not a valid hex number, it doesn't repeat:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x=% ;
%let y=B ;

%put &amp;amp;x  1B&amp;amp;y   ; *hex number duplicates ;
%put &amp;amp;x  1C&amp;amp;y   ; *hex number duplicates ;
%put &amp;amp;x  1D&amp;amp;y   ; *hex number duplicates ;
%put &amp;amp;x  1E&amp;amp;y   ; *hex number duplicates ;
%put &amp;amp;x  1F&amp;amp;y   ; *hex number duplicates ;

%put &amp;amp;x  1G&amp;amp;y   ; *does not duplicate !!! ;
%put &amp;amp;x  1H&amp;amp;y   ; *does not duplicate !!! ;

%put &amp;amp;x  1CG&amp;amp;y  ; *does not duplicate !!! ;
%put &amp;amp;x  1DG&amp;amp;y  ; *does not duplicate !!! ;
%put &amp;amp;x  1EG&amp;amp;y  ; *does not duplicate !!! ;
%put &amp;amp;x  1FG&amp;amp;y  ; *does not duplicate !!! ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Not sure what to infer from that, if anything.&amp;nbsp; But thinking about hex codes made me think about quoting characters and automatic unquoting.... I don't know.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Aug 2023 21:31:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-bug-with-sign/m-p/891599#M352211</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-08-29T21:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable resolution bug with % sign</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-bug-with-sign/m-p/891680#M352241</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1693396421494.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87299i28B0E9A82950EE15/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1693396421494.png" alt="Ksharp_0-1693396421494.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2023 11:53:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-bug-with-sign/m-p/891680#M352241</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-08-30T11:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable resolution bug with % sign</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-bug-with-sign/m-p/892666#M352584</link>
      <description>&lt;P&gt;Thank &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin&lt;/a&gt;&amp;nbsp; for posting this question to community. I have asked SAS IT support and it turns out this is a known bug but not fixed yet. If you see &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p0pnc7p9n4h6g5n16g6js048nhfl.htm" target="_self"&gt;this webpage&lt;/A&gt;, you can find a workaround:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="1.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87608i24650BF062D90464/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This bug fixing process have a more severe impact on the processing of tokens and the change was backed out since there is a fairly easy workaround available in documentation.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2023 02:33:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-resolution-bug-with-sign/m-p/892666#M352584</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2023-09-05T02:33:16Z</dc:date>
    </item>
  </channel>
</rss>

