<?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: date calculation in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/date-calculation/m-p/704887#M26208</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/329198"&gt;@Smitha9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;dataset:&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date&lt;/P&gt;
&lt;P&gt;a_1 03/02/2003&lt;/P&gt;
&lt;P&gt;a_2 04/03/2004&lt;/P&gt;
&lt;P&gt;b_1 05/06/2004&lt;/P&gt;
&lt;P&gt;b_2 06/07/2009&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want the dataset:&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date I want&lt;/P&gt;
&lt;P&gt;a_1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 03/02/2003&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 04/02/2004&lt;/P&gt;
&lt;P&gt;a_2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 04/03/2004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 05/05/2004&lt;/P&gt;
&lt;P&gt;b_1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 05/06/2004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 06/06/2004&lt;/P&gt;
&lt;P&gt;b_2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 06/07/2009&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can I do this in SAS&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Adjusting a date to the same day of the month next month, barring odd requirements for differing lengths of months is easy. You better make sure that we know which of the values is the month and which the day of the month because it is not obvious.&lt;/P&gt;
&lt;P&gt;If you have a date value then you can get the same of the month in the following month using:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Newdate = intnx('month', date,1,'s');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The 'month' is the interval to adjust, one , 1, says adjust for 1 month and the 's' means "same day". Ends of months with 31 days will get mapped to 30 (or 28/29 if the next month is February).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you data is not in mmddyy format then more explicit rules would be needed to even get close&lt;/P&gt;
&lt;P&gt;However, what is the rule for 04/03/2004 becoming 05/05/2004? Or are you implying that we need to look ahead to the next record and set a value? You really need to specify a rule. If the ID plays any role whatever in assigning values then that use, and how, is critical.&lt;/P&gt;</description>
    <pubDate>Wed, 09 Dec 2020 23:04:11 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-12-09T23:04:11Z</dc:date>
    <item>
      <title>date calculation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/date-calculation/m-p/704884#M26205</link>
      <description>&lt;P&gt;dataset:&lt;/P&gt;&lt;P&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date&lt;/P&gt;&lt;P&gt;a_1 03/02/2003&lt;/P&gt;&lt;P&gt;a_2 04/03/2004&lt;/P&gt;&lt;P&gt;b_1 05/06/2004&lt;/P&gt;&lt;P&gt;b_2 06/07/2009&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the dataset:&lt;/P&gt;&lt;P&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date I want&lt;/P&gt;&lt;P&gt;a_1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 03/02/2003&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 04/02/2004&lt;/P&gt;&lt;P&gt;a_2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 04/03/2004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 05/05/2004&lt;/P&gt;&lt;P&gt;b_1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 05/06/2004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 06/06/2004&lt;/P&gt;&lt;P&gt;b_2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 06/07/2009&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can I do this in SAS&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2020 22:49:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/date-calculation/m-p/704884#M26205</guid>
      <dc:creator>Smitha9</dc:creator>
      <dc:date>2020-12-09T22:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: date calculation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/date-calculation/m-p/704885#M26206</link>
      <description>&lt;P&gt;Please advise what rule you are applying to your dates. How does it differ from your previous post about adding one day to your dates?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2020 23:01:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/date-calculation/m-p/704885#M26206</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-12-09T23:01:43Z</dc:date>
    </item>
    <item>
      <title>Re: date calculation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/date-calculation/m-p/704886#M26207</link>
      <description>&lt;P&gt;Do a look-ahead, as described&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Look-Ahead-and-Look-Back/ta-p/475772" target="_blank" rel="noopener"&gt;here&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2020 23:02:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/date-calculation/m-p/704886#M26207</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-09T23:02:48Z</dc:date>
    </item>
    <item>
      <title>Re: date calculation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/date-calculation/m-p/704887#M26208</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/329198"&gt;@Smitha9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;dataset:&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date&lt;/P&gt;
&lt;P&gt;a_1 03/02/2003&lt;/P&gt;
&lt;P&gt;a_2 04/03/2004&lt;/P&gt;
&lt;P&gt;b_1 05/06/2004&lt;/P&gt;
&lt;P&gt;b_2 06/07/2009&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want the dataset:&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date I want&lt;/P&gt;
&lt;P&gt;a_1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 03/02/2003&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 04/02/2004&lt;/P&gt;
&lt;P&gt;a_2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 04/03/2004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 05/05/2004&lt;/P&gt;
&lt;P&gt;b_1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 05/06/2004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 06/06/2004&lt;/P&gt;
&lt;P&gt;b_2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 06/07/2009&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can I do this in SAS&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Adjusting a date to the same day of the month next month, barring odd requirements for differing lengths of months is easy. You better make sure that we know which of the values is the month and which the day of the month because it is not obvious.&lt;/P&gt;
&lt;P&gt;If you have a date value then you can get the same of the month in the following month using:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Newdate = intnx('month', date,1,'s');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The 'month' is the interval to adjust, one , 1, says adjust for 1 month and the 's' means "same day". Ends of months with 31 days will get mapped to 30 (or 28/29 if the next month is February).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you data is not in mmddyy format then more explicit rules would be needed to even get close&lt;/P&gt;
&lt;P&gt;However, what is the rule for 04/03/2004 becoming 05/05/2004? Or are you implying that we need to look ahead to the next record and set a value? You really need to specify a rule. If the ID plays any role whatever in assigning values then that use, and how, is critical.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2020 23:04:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/date-calculation/m-p/704887#M26208</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-09T23:04:11Z</dc:date>
    </item>
    <item>
      <title>Re: date calculation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/date-calculation/m-p/704888#M26209</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/329198"&gt;@Smitha9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;dataset:&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date&lt;/P&gt;
&lt;P&gt;a_1 03/02/2003&lt;/P&gt;
&lt;P&gt;a_2 04/03/2004&lt;/P&gt;
&lt;P&gt;b_1 05/06/2004&lt;/P&gt;
&lt;P&gt;b_2 06/07/2009&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want the dataset:&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date I want&lt;/P&gt;
&lt;P&gt;a_1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 03/02/2003&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 04/02/2004&lt;/P&gt;
&lt;P&gt;a_2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 04/03/2004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 05/05/2004&lt;/P&gt;
&lt;P&gt;b_1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 05/06/2004&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 06/06/2004&lt;/P&gt;
&lt;P&gt;b_2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 06/07/2009&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can I do this in SAS&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, quite easily in a DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In words (which would be a much better topic identity the "date calculation", you apparent want to form date ranges (from current date to just-before the next date):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id :$3. date mmddyy10.;
  format date date9.;
datalines;
a_1 03/02/2003
a_2 04/03/2004
b_1 05/06/2004
b_2 06/07/2009
run;
data want (drop=_:);
   merge have
              have (firstobs=2 keep=date rename=(date=_nxt_date))
  end=end_of_have;
  if end_of_have=0 then  through_date=_nxt_date-1;
  format through_date date9. ;
run;

data _null_; set _last_; put (_all_) (=); run;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The "trick" here is the self merge that merges the second obs (the "firstobs=2" with date renamed to _nxt_date) with the first obs (having the initial date).&amp;nbsp; Then the through_date is just 1 less than _nxt_date, which is calculated for ever instance except the last (because there will be no _nxt_date).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2020 23:05:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/date-calculation/m-p/704888#M26209</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-12-09T23:05:54Z</dc:date>
    </item>
  </channel>
</rss>

