<?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 Date Calculation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-Calculation/m-p/612056#M178512</link>
    <description>&lt;P&gt;I need to compute invoice date based on the following logic,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Logic: 28th day of the prior month as compared to the "Invoice Date" (i.e. if invoice date = 20191213 then date = 20191128. This is fine until you get to the Jan month and gets tricky.&lt;/P&gt;</description>
    <pubDate>Mon, 16 Dec 2019 15:52:12 GMT</pubDate>
    <dc:creator>mauri0623</dc:creator>
    <dc:date>2019-12-16T15:52:12Z</dc:date>
    <item>
      <title>Date Calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Calculation/m-p/612056#M178512</link>
      <description>&lt;P&gt;I need to compute invoice date based on the following logic,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Logic: 28th day of the prior month as compared to the "Invoice Date" (i.e. if invoice date = 20191213 then date = 20191128. This is fine until you get to the Jan month and gets tricky.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 15:52:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Calculation/m-p/612056#M178512</guid>
      <dc:creator>mauri0623</dc:creator>
      <dc:date>2019-12-16T15:52:12Z</dc:date>
    </item>
    <item>
      <title>Re: Date Calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Calculation/m-p/612059#M178513</link>
      <description>&lt;P&gt;It is easy to calculate using INTNX() function.&amp;nbsp; That will let you move a date by any of many intervals, and pick which date in that interval to generate (beginning, end or same).&amp;nbsp; To get to the 28th move to the 1st and add 27.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date = intnx('month',invoice_date,-1,'b')+27;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Dec 2019 16:03:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Calculation/m-p/612059#M178513</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-16T16:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: Date Calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Calculation/m-p/612063#M178516</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181538"&gt;@mauri0623&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As mentioned by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;, the INTNX() is the function you need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	Invoice_date = "20190114";
	date = compress(put(intnx("day",(intnx("month",input(Invoice_date,YYMMDD10.),-1)),27),YYMMDD10.),"-");
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Several functions are nested:&lt;/P&gt;
&lt;P&gt;- The intnx("month",input(Invoice_date,YYMMDD10.),-1) part retrieves the first day of the last month&lt;/P&gt;
&lt;P&gt;- then the intnx("day",&lt;FONT color="#FF0000"&gt;&amp;lt;previous part&amp;gt;&lt;/FONT&gt;, 27) adds 27 days and so retrieves the 28th of the previous month&lt;/P&gt;
&lt;P&gt;- the put and the compress function enable to retrieve the date in character in a human readable way (e.g. 20191128). You can remove this step if you want to keep a date.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 16:13:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Calculation/m-p/612063#M178516</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-12-16T16:13:19Z</dc:date>
    </item>
    <item>
      <title>Re: Date Calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Calculation/m-p/612075#M178519</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/181538"&gt;@mauri0623&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I need to compute invoice date based on the following logic,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Logic: 28th day of the prior month as compared to the "Invoice Date" (i.e. if invoice date = 20191213 then date = 20191128. This is fine until you get to the Jan month and gets tricky.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Is your 20191213 a SAS date value, numeric with a format of YYMMDDN8. ? If that value is a plain number then you really need to convert it to a SAS date value for manipulation.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 16:52:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Calculation/m-p/612075#M178519</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-12-16T16:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: Date Calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-Calculation/m-p/612091#M178528</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp; &amp;nbsp;Appreciate your details but it can be much more concise with the use of format rather than compress&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;YYMMDDn8.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put(intnx("day",(intnx("month",input(Invoice_date,YYMMDD10.),-1)),27),YYMMDDn8. -l);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;- l --&amp;gt; just left aligning the result&lt;/P&gt;</description>
      <pubDate>Mon, 16 Dec 2019 17:35:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-Calculation/m-p/612091#M178528</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-16T17:35:38Z</dc:date>
    </item>
  </channel>
</rss>

