<?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: Adding a leading zero to a month in a macro date variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-leading-zero-to-a-month-in-a-macro-date-variable/m-p/616460#M180478</link>
    <description>&lt;P&gt;Z2 will not drop the leading zero.&amp;nbsp; How are you using the macro variable?&lt;/P&gt;
&lt;P&gt;But if you try to apply the Z2 format to a date you should get ** unless the date is within the first 100 days of 1960.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the month value you need ask for that explicitly.&amp;nbsp; &amp;nbsp;You could try using MMDDYY format and just take the first two characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also don't use SYSDATE as it only includes 2 digit years. You should either Use SYSDATE9 or call the DATE() , also known as the TODAY() function, to get the current date instead of the date when your SAS session started.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1135  %put %sysfunc(putn(7,z2.));
07
1136  %put %sysfunc(intnx(month.1,"&amp;amp;sysdate9"d,-6),mmddyy10.);
07/01/2019
1137  %put %substr(%sysfunc(intnx(month.1,"&amp;amp;sysdate9"d,-6),mmddyy10.),1,2);
07
1138  %put %sysfunc(month(%sysfunc(intnx(month.1,"&amp;amp;sysdate9"d,-6))),z2.);
07&lt;/PRE&gt;</description>
    <pubDate>Fri, 10 Jan 2020 13:40:47 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-01-10T13:40:47Z</dc:date>
    <item>
      <title>Adding a leading zero to a month in a macro date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-leading-zero-to-a-month-in-a-macro-date-variable/m-p/487822#M127128</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a macro where I need to return a two digit value for the prior month.&amp;nbsp; The following macro looks back one month but when I use the z2. format, it drops the 0 in what I need to return as '07'.&amp;nbsp; Is there a format that will return a leading zero for months (Jan - Sep) which would always have a leading zero?&amp;nbsp; I would like to do this in a single line without an extra data step.&amp;nbsp; I am using Base SAS 9.4.&amp;nbsp; Thank you in advance for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mm&amp;nbsp; = %sysfunc(intnx(month.1,"&amp;amp;sysdate"d,-1), z2.);

%put &amp;amp;mm;  (returns 7 instead of the desired 07)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Aug 2018 15:49:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-leading-zero-to-a-month-in-a-macro-date-variable/m-p/487822#M127128</guid>
      <dc:creator>esvenson</dc:creator>
      <dc:date>2018-08-17T15:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a leading zero to a month in a macro date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-leading-zero-to-a-month-in-a-macro-date-variable/m-p/487835#M127135</link>
      <description>&lt;P&gt;Your macro didn't result in 7 as your code requires correction in the first place I am afraid. And then the use of month function is also missing like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mm  = %sysfunc(intnx(month.1,%sysevalf("&amp;amp;sysdate"d),-1));
%let _mm=%sysfunc(month(&amp;amp;mm),z2.);
%put  &amp;amp;_mm; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course you can combine the mm and _mm in one expression but my eyes hurt looking at very long expressions&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 16:34:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-leading-zero-to-a-month-in-a-macro-date-variable/m-p/487835#M127135</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-17T16:34:54Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a leading zero to a month in a macro date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-leading-zero-to-a-month-in-a-macro-date-variable/m-p/487838#M127137</link>
      <description>&lt;P&gt;Thank you so much novinosrin!&amp;nbsp; I was able to combine the two lines you&amp;nbsp;shared into one to make it a little more streamlined.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a great day!&lt;/P&gt;&lt;P&gt;- E&lt;/P&gt;</description>
      <pubDate>Fri, 17 Aug 2018 16:52:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-leading-zero-to-a-month-in-a-macro-date-variable/m-p/487838#M127137</guid>
      <dc:creator>esvenson</dc:creator>
      <dc:date>2018-08-17T16:52:11Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a leading zero to a month in a macro date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-leading-zero-to-a-month-in-a-macro-date-variable/m-p/616453#M180471</link>
      <description>&lt;P&gt;Would you mind sharing that line please? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 13:25:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-leading-zero-to-a-month-in-a-macro-date-variable/m-p/616453#M180471</guid>
      <dc:creator>bjarkeahm</dc:creator>
      <dc:date>2020-01-10T13:25:20Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a leading zero to a month in a macro date variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-leading-zero-to-a-month-in-a-macro-date-variable/m-p/616460#M180478</link>
      <description>&lt;P&gt;Z2 will not drop the leading zero.&amp;nbsp; How are you using the macro variable?&lt;/P&gt;
&lt;P&gt;But if you try to apply the Z2 format to a date you should get ** unless the date is within the first 100 days of 1960.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the month value you need ask for that explicitly.&amp;nbsp; &amp;nbsp;You could try using MMDDYY format and just take the first two characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also don't use SYSDATE as it only includes 2 digit years. You should either Use SYSDATE9 or call the DATE() , also known as the TODAY() function, to get the current date instead of the date when your SAS session started.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1135  %put %sysfunc(putn(7,z2.));
07
1136  %put %sysfunc(intnx(month.1,"&amp;amp;sysdate9"d,-6),mmddyy10.);
07/01/2019
1137  %put %substr(%sysfunc(intnx(month.1,"&amp;amp;sysdate9"d,-6),mmddyy10.),1,2);
07
1138  %put %sysfunc(month(%sysfunc(intnx(month.1,"&amp;amp;sysdate9"d,-6))),z2.);
07&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Jan 2020 13:40:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-leading-zero-to-a-month-in-a-macro-date-variable/m-p/616460#M180478</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-10T13:40:47Z</dc:date>
    </item>
  </channel>
</rss>

