<?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 SAS sometimes adds whitespace before macro variable when running a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-sometimes-adds-whitespace-before-macro-variable-when-running/m-p/758017#M239304</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was just recently using a quite large macro which is used for calculating ratios. After running the macro, I got the following syntax error message:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, (, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, 
              GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, [, ^=, {, |, ||, ~=.  &lt;/PRE&gt;&lt;P&gt;The code inside the macro where the error occurs is the following:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let p_gen = _p1;&lt;BR /&gt;data new; &lt;BR /&gt;set old; &lt;BR /&gt;...&lt;BR /&gt;w725000&amp;amp;p_gen = sum(0, w240000&amp;amp;p_gen, -w239000&amp;amp;p_gen, w239010&amp;amp;p_gen);&lt;BR /&gt;...&lt;BR /&gt;run;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Basically what happens is that SAS does not translate the macro variable properly and adds whitespace before the macro variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What SAS should do:&amp;nbsp;&lt;CODE class=" language-sas"&gt;w240000_p1&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;What SAS does:&amp;nbsp;&amp;nbsp;&lt;CODE class=" language-sas"&gt;w240000 p1&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;And obviously that does not really work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please tell me the reason behind this strange bug, since the workaround can be quite tedious.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Btw I am working in SAS EG 7.1.&lt;/P&gt;&lt;P&gt;Thanks a lot and kind regards&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Paul&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 29 Jul 2021 09:45:02 GMT</pubDate>
    <dc:creator>PvH</dc:creator>
    <dc:date>2021-07-29T09:45:02Z</dc:date>
    <item>
      <title>SAS sometimes adds whitespace before macro variable when running a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-sometimes-adds-whitespace-before-macro-variable-when-running/m-p/758017#M239304</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was just recently using a quite large macro which is used for calculating ratios. After running the macro, I got the following syntax error message:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, (, *, **, +, ',', -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =, &amp;gt;, &amp;gt;&amp;lt;, &amp;gt;=, AND, EQ, GE, 
              GT, IN, LE, LT, MAX, MIN, NE, NG, NL, NOTIN, OR, [, ^=, {, |, ||, ~=.  &lt;/PRE&gt;&lt;P&gt;The code inside the macro where the error occurs is the following:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let p_gen = _p1;&lt;BR /&gt;data new; &lt;BR /&gt;set old; &lt;BR /&gt;...&lt;BR /&gt;w725000&amp;amp;p_gen = sum(0, w240000&amp;amp;p_gen, -w239000&amp;amp;p_gen, w239010&amp;amp;p_gen);&lt;BR /&gt;...&lt;BR /&gt;run;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Basically what happens is that SAS does not translate the macro variable properly and adds whitespace before the macro variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What SAS should do:&amp;nbsp;&lt;CODE class=" language-sas"&gt;w240000_p1&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;What SAS does:&amp;nbsp;&amp;nbsp;&lt;CODE class=" language-sas"&gt;w240000 p1&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;And obviously that does not really work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please tell me the reason behind this strange bug, since the workaround can be quite tedious.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Btw I am working in SAS EG 7.1.&lt;/P&gt;&lt;P&gt;Thanks a lot and kind regards&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Paul&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 09:45:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-sometimes-adds-whitespace-before-macro-variable-when-running/m-p/758017#M239304</guid>
      <dc:creator>PvH</dc:creator>
      <dc:date>2021-07-29T09:45:02Z</dc:date>
    </item>
    <item>
      <title>Re: SAS sometimes adds whitespace before macro variable when running a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-sometimes-adds-whitespace-before-macro-variable-when-running/m-p/758021#M239306</link>
      <description>&lt;P&gt;This can happen if you used any macro quoting for the variable. With a simple content like&lt;/P&gt;
&lt;PRE&gt;_p1&lt;/PRE&gt;
&lt;P&gt;this should not be necessary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See this piece of reference code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options symbolgen;

%let p_gen = _p1;

data test;
xxx&amp;amp;p_gen.yyy = 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can see that you do not get blanks, in the log (no ERROR) and in the dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So it is essential to know what happens between the %LET and the use of the macro variable in the data step.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 09:58:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-sometimes-adds-whitespace-before-macro-variable-when-running/m-p/758021#M239306</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-07-29T09:58:22Z</dc:date>
    </item>
    <item>
      <title>Re: SAS sometimes adds whitespace before macro variable when running a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-sometimes-adds-whitespace-before-macro-variable-when-running/m-p/758108#M239346</link>
      <description>&lt;P&gt;It looks more like the underscore is being changed to a blank.&amp;nbsp; It does not look like SAS is pre-pending a blank.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's not normal behavior for SAS to change underscores to blanks.&amp;nbsp; Can you post more of your code?&amp;nbsp; The point at which you have ". . ." may have something going on in it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How are you determining that SAS is converting the underscore to a space?&amp;nbsp; This isn't normally what SAS does, so I'm wonder if this is really what is happening.&amp;nbsp; Maybe the error message is somehow misleading.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This in particular looks odd to me:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt; -w239000&amp;amp;p_gen&lt;/LI-CODE&gt;
&lt;P&gt;What is the negative sign doing there?&amp;nbsp; If w239000&amp;amp;p_gen is a variable name, then I would think you would want something like:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;(-1 * w239000&amp;amp;p_gen)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 14:34:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-sometimes-adds-whitespace-before-macro-variable-when-running/m-p/758108#M239346</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-07-29T14:34:55Z</dc:date>
    </item>
  </channel>
</rss>

