<?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: SAS date and data steps in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-and-data-steps/m-p/820214#M323720</link>
    <description>&lt;P&gt;Do NOT format macro variables that contain dates (unless you want to use them in titles or labels. which does not appear to be the case here as you want to use this macro variable in a data step). See &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 28&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let offmnth = %sysfunc(intnx(month, %sysfunc(today()), -1));
data  test&amp;amp;offmnth;
   a= &amp;amp;offmnth;
   put 'SAS date=' a;
   put 'formatted date=' a date9.;
   put 'formatted date=' a ddmmyyn6.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;For example, since we are now as of time of writing in June 2022, I would want 010522&amp;nbsp; NOT&amp;nbsp; 23767.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Unless you have some strict requirement, do not use 2 digit years, use 4 digit years, in which case use format ddmmyyn8.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;SAS Dates are recorded in the number of days since 01JAN1960, and so you DO want 23767, which will work properly when you perform any aritmetic or logical operations in the DATA step, and can be made to appear as an actual date by using a format.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 24 Jun 2022 11:26:38 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-06-24T11:26:38Z</dc:date>
    <item>
      <title>SAS date and data steps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-and-data-steps/m-p/820170#M323703</link>
      <description>&lt;P&gt;Hello, I am trying to&amp;nbsp; use the first of the month as the date for a dataset. however, all I am able to come up with is the actual&amp;nbsp; &amp;nbsp;SAS&amp;nbsp; day since Jan 1960.&amp;nbsp; For example, since we are now as of time of writing in June 2022, I would want 010522&amp;nbsp; NOT&amp;nbsp; 23767.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%let offmnth = %sysfunc(intnx(month, %sysfunc(today()), -1),ddmmmyy.);


data  test&amp;amp;offmnth;
   a= &amp;amp;offmnth;
   put 'SAS date='a;
    put 'formatted date='a date9.;
	run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Jun 2022 23:34:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-and-data-steps/m-p/820170#M323703</guid>
      <dc:creator>goldenone</dc:creator>
      <dc:date>2022-06-23T23:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date and data steps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-and-data-steps/m-p/820174#M323705</link>
      <description>&lt;P&gt;I find it often easier to debug one of these nested %sysfunc() expressions using a SAS data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  s1=today();
  s2=intnx('month',today(),-1,'b');
  s3=put(intnx('month',today(),-1,'b'),ddmmmyy.);
run;
proc print data=test;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In doing so you'd easily spot that you're using a wrong format name.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1656029787155.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72706i303CBC256F0F4697/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1656029787155.png" alt="Patrick_0-1656029787155.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If you fix the format then you'll get what you're after&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let offmnth = %sysfunc(intnx(month, %sysfunc(today()), -1,b),ddmmyyn.);
%put &amp;amp;=offmnth;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_1-1656029866841.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72707i0F560F11BABA6122/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_1-1656029866841.png" alt="Patrick_1-1656029866841.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If this is just about creating some macro variables then you could also just stick with the data _null_ step because it's imho easier to develop, read and maintain.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  dt=intnx('month',today(),-1,'b');
  call symputx('offmnth',put(dt,ddmmyyn.));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Jun 2022 00:20:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-and-data-steps/m-p/820174#M323705</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-06-24T00:20:33Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date and data steps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-and-data-steps/m-p/820179#M323710</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/47284"&gt;@goldenone&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello, I am trying to&amp;nbsp; use the first of the month as the date for a dataset. however, all I am able to come up with is the actual&amp;nbsp; &amp;nbsp;SAS&amp;nbsp; day since Jan 1960.&amp;nbsp; For example, since we are now as of time of writing in June 2022, I would want 010522&amp;nbsp; NOT&amp;nbsp; 23767.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;%let offmnth = %sysfunc(intnx(month, %sysfunc(today()), -1),ddmmmyy.);


data  test&amp;amp;offmnth;
   a= &amp;amp;offmnth;
   put 'SAS date='a;
    put 'formatted date='a date9.;
	run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your %SYSFUNC() call is not using a valid FORMAT, there is no format named DDMMMYY.&amp;nbsp; If you want print a date in Day Month Year order use the DDMMYY format.&amp;nbsp; If you want it without any separator use the DDMMYYN format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the number&amp;nbsp;23,767 &lt;STRONG&gt;is the actual DATE&lt;/STRONG&gt; since SAS records dates as number of days since 1960.&amp;nbsp; &amp;nbsp;The &lt;STRONG&gt;number&amp;nbsp;10,522 is NOT a DATE value&lt;/STRONG&gt;.&amp;nbsp; And what date value would that number even mean?&amp;nbsp; Is that Oct 5, 1922?&amp;nbsp; Oct 5 2022? May 22nd, 1910?&amp;nbsp; Jan 1st, 2022? May 1st, 1922?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need to use the value as a date then store it as a date value.&amp;nbsp; Then you can compare it with other dates, sort it, group it.&amp;nbsp; If you have it print in a style that humans will recognize then use a FORMAT.&amp;nbsp; But do not use DDMMYY strings (or worse number in DDM,MYY style) to store dates.&amp;nbsp; It will cause confusion.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you use either DMY or DMY order you will confuse half of your audience. (and if you use only two digits for the year make that ALL of your audience).&amp;nbsp; Use either the DATE or YYMMDD format to avoid confusion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Plus if you use that digit string as part of a DATASET name then you really want to use YMD order so that the filenames will sort into chronological order.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let offmnth = %sysfunc(intnx(month, %sysfunc(today()), -1),yymmddn8.);

data test&amp;amp;offmnth;
   date = input("&amp;amp;offmnth",yymmdd8.);
   format date date9.;
   put "Digits are &amp;amp;offmnth..  Raw date is: " date :comma7.  date= ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Digits are 20220501.  Raw date is: 22,766 date=01MAY2022
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2022 02:23:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-and-data-steps/m-p/820179#M323710</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-24T02:23:15Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date and data steps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-and-data-steps/m-p/820182#M323712</link>
      <description>&lt;P&gt;When time-stamping files, always use a YMD order; it is much better to handle (files sort automatically, and periods are easy found with wildcards).&lt;/P&gt;
&lt;P&gt;Always use 4-digit years for formatted dates.&lt;/P&gt;
&lt;P&gt;Re-convert the formatted macro variable with the INPUT fuhction.&lt;/P&gt;
&lt;P&gt;Assign a format in the data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let offmnth = %sysfunc(intnx(month, %sysfunc(today()), -1, b),yymmddn8.);

data  test&amp;amp;offmnth.;
a = input("&amp;amp;offmnth.",yymmdd8.);
format a yymmdd10.;
put 'SAS date='a 5.;
put 'formatted date='a date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Jun 2022 04:04:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-and-data-steps/m-p/820182#M323712</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-06-24T04:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: SAS date and data steps</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-date-and-data-steps/m-p/820214#M323720</link>
      <description>&lt;P&gt;Do NOT format macro variables that contain dates (unless you want to use them in titles or labels. which does not appear to be the case here as you want to use this macro variable in a data step). See &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 28&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let offmnth = %sysfunc(intnx(month, %sysfunc(today()), -1));
data  test&amp;amp;offmnth;
   a= &amp;amp;offmnth;
   put 'SAS date=' a;
   put 'formatted date=' a date9.;
   put 'formatted date=' a ddmmyyn6.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;For example, since we are now as of time of writing in June 2022, I would want 010522&amp;nbsp; NOT&amp;nbsp; 23767.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Unless you have some strict requirement, do not use 2 digit years, use 4 digit years, in which case use format ddmmyyn8.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;SAS Dates are recorded in the number of days since 01JAN1960, and so you DO want 23767, which will work properly when you perform any aritmetic or logical operations in the DATA step, and can be made to appear as an actual date by using a format.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2022 11:26:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-date-and-data-steps/m-p/820214#M323720</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-24T11:26:38Z</dc:date>
    </item>
  </channel>
</rss>

