<?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 get Last date of each month for severalyears in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-Last-date-of-each-month-for-severalyears/m-p/902240#M356533</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
do year=2020 to 2023;
 do month=1 to 12;
   date=mdy(month,1,year);
   last_day=mdy(ifn(month=12,1,month+1),1,ifn(month=12,year+1,year))-date;
   last_date=mdy(month,last_day,year);
   output;
 end;
end;
format last_date date yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 09 Nov 2023 03:09:18 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2023-11-09T03:09:18Z</dc:date>
    <item>
      <title>how to get Last date of each month for severalyears</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-Last-date-of-each-month-for-severalyears/m-p/902004#M356422</link>
      <description>&lt;P&gt;Can any one explain how can we get last date of each month for several years without using intnx function.&lt;/P&gt;&lt;P&gt;because intnx was introduced in 9.2 and above.&lt;/P&gt;&lt;P&gt;i want to know how previous coders code in this particular situation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2023 04:26:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-Last-date-of-each-month-for-severalyears/m-p/902004#M356422</guid>
      <dc:creator>rogeralfa111</dc:creator>
      <dc:date>2023-11-08T04:26:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to get Last date of each month for severalyears</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-Last-date-of-each-month-for-severalyears/m-p/902009#M356425</link>
      <description>&lt;P&gt;Soemthing like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select (month);
  when (1,3,5,7,8,10,12) day = 31;
  when(4,6,9,11) day = 30;
  when (2) do;
    if mod(year,4) ne 0 and (mod(year,400) = 0 or mod(year,100) ne 0)
    then day = 29;
    else day = 28;
  end;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2023 07:18:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-Last-date-of-each-month-for-severalyears/m-p/902009#M356425</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-11-08T07:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to get Last date of each month for severalyears</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-Last-date-of-each-month-for-severalyears/m-p/902011#M356426</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/433943"&gt;@rogeralfa111&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Can any one explain how can we get last date of each month for several years without using intnx function.&lt;/P&gt;
&lt;P&gt;because intnx was introduced in 9.2 and above.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I assume this is an academic question.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The intnx() function existed with certainty already in versions prior to 9.2. No more sure if it was already V6 but certainly since V8.&amp;lt;n&amp;gt;&lt;/P&gt;
&lt;P&gt;Here a link to V9.1.3 docu that includes intnx():&amp;nbsp;&lt;A href="https://support.sas.com/documentation/onlinedoc/91pdf/sasdoc_913/base_lrdictionary_10307.pdf" target="_blank" rel="noopener"&gt;SAS 9.1.3 Language Reference: Dictionary, Fifth Edition&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...or here a link to SAS V8 docu I found:&amp;nbsp;&lt;A href="https://www.sfu.ca/sasdoc/sashtml/lgref/z0212700.htm" target="_blank" rel="noopener"&gt;https://www.sfu.ca/sasdoc/sashtml/lgref/z0212700.htm&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below a lazy approach that doesn't need separate logic for the different number of days per month or for dealing with leap years.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.last_day_of_month;
  format date date9.;
  do date='01jan1900'd to today();
    if day(date+1)=1 then
      do;
        output;
        date+27;
      end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;...and of course with a given date you can just use the following test: day(date+1)=1&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2023 09:48:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-Last-date-of-each-month-for-severalyears/m-p/902011#M356426</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-11-08T09:48:12Z</dc:date>
    </item>
    <item>
      <title>Re: how to get Last date of each month for severalyears</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-Last-date-of-each-month-for-severalyears/m-p/902098#M356467</link>
      <description>&lt;P&gt;There are a number of books on common numeric calculations and dates is one of them.&lt;/P&gt;
&lt;P&gt;However be a bit careful with FEBRUARY and years as some references didn't consider the year 2000, which was an exception to the common 100/400 year determination of Leap Years (hence a problem called Y2K). Be very careful of any code relying on 2-digit years because that is a symptom of problems to come.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2023 16:39:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-Last-date-of-each-month-for-severalyears/m-p/902098#M356467</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-11-08T16:39:31Z</dc:date>
    </item>
    <item>
      <title>Re: how to get Last date of each month for severalyears</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-Last-date-of-each-month-for-severalyears/m-p/902101#M356470</link>
      <description>&lt;P&gt;Historically, I've also created a date dimension and queried the table.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://gist.github.com/statgeek/9606118" target="_blank" rel="noopener"&gt;https://gist.github.com/statgeek/9606118&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDIT: the holiday portion would need to be updated (clearly very old code)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2023 16:59:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-Last-date-of-each-month-for-severalyears/m-p/902101#M356470</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-11-08T16:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to get Last date of each month for severalyears</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-Last-date-of-each-month-for-severalyears/m-p/902240#M356533</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
do year=2020 to 2023;
 do month=1 to 12;
   date=mdy(month,1,year);
   last_day=mdy(ifn(month=12,1,month+1),1,ifn(month=12,year+1,year))-date;
   last_date=mdy(month,last_day,year);
   output;
 end;
end;
format last_date date yymmdd10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Nov 2023 03:09:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-Last-date-of-each-month-for-severalyears/m-p/902240#M356533</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-11-09T03:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: how to get Last date of each month for severalyears</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-Last-date-of-each-month-for-severalyears/m-p/902250#M356538</link>
      <description>&lt;P&gt;For each year/month, get the date value for the first day of next month.&amp;nbsp; Then subtract 1:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do year=2020 to 2023;
    do month=1 to 12;
      nxt_date1=mdy(mod(month,12)+1,1,year+(month=12));  *Next month first date *;
      last_date=nxt_date1-1;
      last_day=day(last_date);
      output;
    end;
  end;
  format nxt_date1 date9.  last_date date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2023 03:56:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-Last-date-of-each-month-for-severalyears/m-p/902250#M356538</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-11-09T03:56:20Z</dc:date>
    </item>
  </channel>
</rss>

