<?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: Used function cat for numeric number with format zw. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Used-function-cat-for-numeric-number-with-format-zw/m-p/411865#M100691</link>
    <description>&lt;P&gt;Oh, and to fix it just do:&lt;/P&gt;
&lt;PRE&gt;%let x1=2010;
%let x2=01;
%let x3=&amp;amp;x1.M&amp;amp;x2.;
%put &amp;amp;x3.;&lt;/PRE&gt;
&lt;P&gt;You don't need cat() at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will find this post helpful:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/General-SAS-Programming/Why-is-CAT-removing-leading-zeros/td-p/329883" target="_blank"&gt;https://communities.sas.com/t5/General-SAS-Programming/Why-is-CAT-removing-leading-zeros/td-p/329883&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As always, the problem lies with doing data processing in macro language.&amp;nbsp; Macro is for generating text, nothing more, and has limited functionality.&amp;nbsp; In your case the cat() function is treating 01 as numeric, which is 1.&amp;nbsp; You can use put in there as well, however best method is to use the tool appropriate to the task, and data processing is best done in Base SAS - in fact macro is just an addon.&lt;/P&gt;</description>
    <pubDate>Thu, 09 Nov 2017 10:49:04 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-11-09T10:49:04Z</dc:date>
    <item>
      <title>Used function cat for numeric number with format zw.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Used-function-cat-for-numeric-number-with-format-zw/m-p/411844#M100684</link>
      <description>&lt;PRE class="tw-data-text tw-ta tw-text-small"&gt;&lt;SPAN&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I can not understand why cat does not take into account the zeros in this example.&lt;BR /&gt;The length of the macro variable x3 is 2 for months &amp;lt;10 after put (x2,Z2.).
Another question, why the repeat function when the number of repetitions equal to 0 &lt;BR /&gt;adds the 0 (which explains the use of the loop)&lt;BR /&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro remplir();
%DO LOOP=7 %to 12;
%LET x1=%SYSFUNC(INTNX(month,%SYSFUNC(INTNX(day,%SYSFUNC(today()),%SYSFUNC(day(%SYSFUNC(today())))-1)),&amp;amp;LOOP.-19));
%LET x2=%SYSFUNC(MONTH(&amp;amp;x1.));
%LET x3=%SYSFUNC(PUTN(&amp;amp;x2., Z2.));
%let len=%length(&amp;amp;x3.);
%let len1=%length(&amp;amp;x2.);
%LET val1=&amp;amp;x1.;
%LET val12=%SYSFUNC(CAT(%SYSFUNC(PUTN(&amp;amp;x1.,year2.)),M,&amp;amp;x3.));
%LET val13=%SYSFUNC(CAT(%SYSFUNC(PUTN(&amp;amp;x1.,year2.)),M,%sysfunc(repeat(0,%eval(2-%length(&amp;amp;x2.)))) ,&amp;amp;x2.));
%if &amp;amp;len1.=1 %then %do;
%LET val14=%SYSFUNC(CAT(%SYSFUNC(PUTN(&amp;amp;x1.,year2.)),M,%sysfunc(repeat(0,%eval(2-%length(&amp;amp;x2.)))) ,&amp;amp;x2.));
%end;
%else %do;
%LET val14=%SYSFUNC(CAT(%SYSFUNC(PUTN(&amp;amp;x1.,year2.)),M,&amp;amp;x3.));
%end;
%put &amp;amp;=x3/&amp;amp;=len./&amp;amp;=val12./&amp;amp;=val12./&amp;amp;=val13./&amp;amp;=val14.;
%end;
%mend remplir;
%remplir; &lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE class="tw-data-text tw-ta tw-text-small"&gt;&lt;SPAN&gt;/**************/&lt;BR /&gt;      Log&lt;BR /&gt;/*************/&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;DIV class="bbcode_quote_container"&gt;&amp;nbsp;Log&lt;/DIV&gt;&lt;PRE class="tw-data-text tw-ta tw-text-small"&gt;X3=11/LEN=2/VAL12=16M11/VAL12=16M11/VAL13=16M011/VAL14=16M11&lt;BR /&gt; X3=12/LEN=2/VAL12=16M12/VAL12=16M12/VAL13=16M012/VAL14=16M12&lt;BR /&gt; X3=01/LEN=2/VAL12=17M1/VAL12=17M1/VAL13=17M01/VAL14=17M01&lt;BR /&gt; X3=02/LEN=2/VAL12=17M2/VAL12=17M2/VAL13=17M02/VAL14=17M02&lt;BR /&gt; X3=03/LEN=2/VAL12=17M3/VAL12=17M3/VAL13=17M03/VAL14=17M03&lt;BR /&gt; X3=04/LEN=2/VAL12=17M4/VAL12=17M4/VAL13=17M04/VAL14=17M04 &lt;/PRE&gt;&lt;DIV class="_Ejb"&gt;&lt;DIV&gt;&lt;DIV class="tw-ta-container tw-nfl"&gt;&lt;PRE class="tw-data-text tw-ta tw-text-large"&gt;&lt;SPAN&gt;cordially&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2017 09:34:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Used-function-cat-for-numeric-number-with-format-zw/m-p/411844#M100684</guid>
      <dc:creator>mansour_ibrahim</dc:creator>
      <dc:date>2017-11-09T09:34:37Z</dc:date>
    </item>
    <item>
      <title>Re: Used function cat for numeric number with format zw.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Used-function-cat-for-numeric-number-with-format-zw/m-p/411848#M100685</link>
      <description>&lt;P&gt;Why, in $DEITY's name, are you doing that in a macro? The macro facility is a CODE GENERATOR, not a DATA PROCESSOR!!!. Use a data step!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That %sysfunc avalanche is a cancer-causing eyesore.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the data step, use put's whenever you assign/create a variable, to see how your data is modified. The data step also notifies you of all automatical type conversions where formats might be lost.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2017 09:57:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Used-function-cat-for-numeric-number-with-format-zw/m-p/411848#M100685</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-09T09:57:43Z</dc:date>
    </item>
    <item>
      <title>Re: Used function cat for numeric number with format zw.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Used-function-cat-for-numeric-number-with-format-zw/m-p/411849#M100686</link>
      <description>&lt;P&gt;Sorry, that code is nigh on impossible to read.&amp;nbsp; Why not use a simple datastep to achieve your goal?&lt;/P&gt;
&lt;PRE&gt;data _null_;
  do i=7 to 12;
    /* do some things here */
  end;
  call symput('len',lengthn(...));
...
run;
&lt;/PRE&gt;
&lt;P&gt;Though I can't actually see why you would need all those macro variables in the first place.&amp;nbsp; It would be far simpler if you put the calculation output in datasets and used merges - or are you planning on using this information in filenames/dataset names?&amp;nbsp; If so consider doing all the programming using one dataset and split it out at the end - will simplfy coding quite a bit.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2017 10:00:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Used-function-cat-for-numeric-number-with-format-zw/m-p/411849#M100686</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-09T10:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: Used function cat for numeric number with format zw.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Used-function-cat-for-numeric-number-with-format-zw/m-p/411862#M100690</link>
      <description>&lt;P&gt;Thank you for your answers&lt;/P&gt;&lt;P&gt;I simplify the example.&lt;/P&gt;&lt;P&gt;Why cat does not take into account the 0?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let x1=2010;
%LET x2=01;
%LET x3=%SYSFUNC(CAT(&amp;amp;x1.,M,&amp;amp;x2.));
%put &amp;amp;x3.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Nov 2017 10:36:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Used-function-cat-for-numeric-number-with-format-zw/m-p/411862#M100690</guid>
      <dc:creator>mansour_ibrahim</dc:creator>
      <dc:date>2017-11-09T10:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: Used function cat for numeric number with format zw.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Used-function-cat-for-numeric-number-with-format-zw/m-p/411865#M100691</link>
      <description>&lt;P&gt;Oh, and to fix it just do:&lt;/P&gt;
&lt;PRE&gt;%let x1=2010;
%let x2=01;
%let x3=&amp;amp;x1.M&amp;amp;x2.;
%put &amp;amp;x3.;&lt;/PRE&gt;
&lt;P&gt;You don't need cat() at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will find this post helpful:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/General-SAS-Programming/Why-is-CAT-removing-leading-zeros/td-p/329883" target="_blank"&gt;https://communities.sas.com/t5/General-SAS-Programming/Why-is-CAT-removing-leading-zeros/td-p/329883&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As always, the problem lies with doing data processing in macro language.&amp;nbsp; Macro is for generating text, nothing more, and has limited functionality.&amp;nbsp; In your case the cat() function is treating 01 as numeric, which is 1.&amp;nbsp; You can use put in there as well, however best method is to use the tool appropriate to the task, and data processing is best done in Base SAS - in fact macro is just an addon.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2017 10:49:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Used-function-cat-for-numeric-number-with-format-zw/m-p/411865#M100691</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-09T10:49:04Z</dc:date>
    </item>
    <item>
      <title>Re: Used function cat for numeric number with format zw.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Used-function-cat-for-numeric-number-with-format-zw/m-p/411880#M100694</link>
      <description>&lt;P&gt;cat DOES take leading zeroes into account:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
x1 = '2017';
x2 = '09';
x3 = cat(x1,'M',x2);
put x3=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;2017M09&lt;/PRE&gt;
&lt;P&gt;But try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
x1 = 2017;
x2 = 09;
x3 = cat(x1,'M',x2);
put x3=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;x3=2017M9&lt;/PRE&gt;
&lt;P&gt;So you can see that your "problem" comes from your abuse of the macro facility.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2017 11:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Used-function-cat-for-numeric-number-with-format-zw/m-p/411880#M100694</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-09T11:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: Used function cat for numeric number with format zw.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Used-function-cat-for-numeric-number-with-format-zw/m-p/411976#M100722</link>
      <description>&lt;P&gt;Looks like an awful lot of work to simulate the use of the YYMMw. format with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Generally you are better off leaving dates as date values until a human has to read them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance&lt;/P&gt;
&lt;PRE&gt;data _null_;
   x= '15Dec2016'd;
   put x yymm5.;
run;&lt;/PRE&gt;
&lt;P&gt;which is the value of your macro variables Val12 and Val14 on the second line of log output. (picked on December of personal reasons)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2017 15:46:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Used-function-cat-for-numeric-number-with-format-zw/m-p/411976#M100722</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-11-09T15:46:22Z</dc:date>
    </item>
  </channel>
</rss>

