<?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: how to concat a string in a %let var using '0'? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-concat-a-string-in-a-let-var-using-0/m-p/802345#M315857</link>
    <description>&lt;P&gt;There is no need to use CATxx() function in macro code.&amp;nbsp; Macro code is just text substitution!&amp;nbsp; So just put the text where you want it to appear.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let a = %substr(&amp;amp;a.,1,4)01;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And to make things worse the %SYSFUNC() macro function does not play that well with SAS functions that allow either numeric or character values for some of their arguments.&amp;nbsp; Like the CATxxx() function do.&amp;nbsp; This is because everything is a text to the macro processor, but the SAS functions want to know whether they are being given a number or a string.&amp;nbsp; When you call them in a data step they know what you are giving them.&amp;nbsp; So %SYSFUNC() tries to GUESS whether the text in your macro call should be considered a number or a string. The text 01 looks like a number.&amp;nbsp; And there is no different between the numbers 1 and 01 and 00001 they all mean the same number.&amp;nbsp; So CATT() says, thanks I'll convert the number 1 into a string and concatenate it to the other arguments.&amp;nbsp; And poof their goes your 0 digit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 15 Mar 2022 21:00:02 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-03-15T21:00:02Z</dc:date>
    <item>
      <title>how to concat a string in a %let var using '0'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-concat-a-string-in-a-let-var-using-0/m-p/802334#M315850</link>
      <description>&lt;P&gt;hi there!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have to concat a string in a %let variable, however when i use '0' is the same that zero don't exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;follow my code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro b();
        
           %let a=202102 ;
         	%let a = %sysfunc(catt(%sysfunc(substr(&amp;amp;a.,1,4)),%STR(01)));
           %put &amp;amp;a;
        
%mend b;
%pippo;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;the result should be: 202101 however i got 20211.&lt;/P&gt;
&lt;P&gt;If i change '0' to any other number it works.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 20:12:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-concat-a-string-in-a-let-var-using-0/m-p/802334#M315850</guid>
      <dc:creator>erickdt</dc:creator>
      <dc:date>2022-03-15T20:12:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to concat a string in a %let var using '0'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-concat-a-string-in-a-let-var-using-0/m-p/802340#M315854</link>
      <description>&lt;P&gt;Way too much code:&lt;/P&gt;
&lt;PRE&gt; %let a=202102 ;
 %let a = %substr(&amp;amp;a.,1,4)01;
 %put &amp;amp;a;&lt;/PRE&gt;
&lt;P&gt;First, there&amp;nbsp; is a macro %substr function so no reason to go use %sysfunc for that. The way the macro processor works strings are pretty much appended as is unless one of them might contain macro trigger, i.e. &amp;amp; or %.&lt;/P&gt;
&lt;P&gt;You often need to use the Macro processor concatenate operator . (dot) when appending text directly to a macro variable&amp;nbsp; as in : %let newvar = &amp;amp;var.sometext; otherwise the macro processor looks for a macro variable named Varsometext (probably not finding it).&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 20:45:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-concat-a-string-in-a-let-var-using-0/m-p/802340#M315854</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-15T20:45:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to concat a string in a %let var using '0'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-concat-a-string-in-a-let-var-using-0/m-p/802341#M315855</link>
      <description>This works:&lt;BR /&gt;%let a = %sysfunc(catt(%sysfunc(substr(&amp;amp;a.,1,4)),%STR(0),%STR(1)));</description>
      <pubDate>Tue, 15 Mar 2022 20:48:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-concat-a-string-in-a-let-var-using-0/m-p/802341#M315855</guid>
      <dc:creator>pink_poodle</dc:creator>
      <dc:date>2022-03-15T20:48:31Z</dc:date>
    </item>
    <item>
      <title>Re: how to concat a string in a %let var using '0'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-concat-a-string-in-a-let-var-using-0/m-p/802345#M315857</link>
      <description>&lt;P&gt;There is no need to use CATxx() function in macro code.&amp;nbsp; Macro code is just text substitution!&amp;nbsp; So just put the text where you want it to appear.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let a = %substr(&amp;amp;a.,1,4)01;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And to make things worse the %SYSFUNC() macro function does not play that well with SAS functions that allow either numeric or character values for some of their arguments.&amp;nbsp; Like the CATxxx() function do.&amp;nbsp; This is because everything is a text to the macro processor, but the SAS functions want to know whether they are being given a number or a string.&amp;nbsp; When you call them in a data step they know what you are giving them.&amp;nbsp; So %SYSFUNC() tries to GUESS whether the text in your macro call should be considered a number or a string. The text 01 looks like a number.&amp;nbsp; And there is no different between the numbers 1 and 01 and 00001 they all mean the same number.&amp;nbsp; So CATT() says, thanks I'll convert the number 1 into a string and concatenate it to the other arguments.&amp;nbsp; And poof their goes your 0 digit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Mar 2022 21:00:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-concat-a-string-in-a-let-var-using-0/m-p/802345#M315857</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-15T21:00:02Z</dc:date>
    </item>
  </channel>
</rss>

