<?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: Reverse engineer dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reverse-engineer-dates/m-p/334990#M75719</link>
    <description>&lt;P&gt;Is this what you're looking for? If there is a rule for which days are always considered exceptions, then we could try programming that, but without that knowledge, I've hardcoded the exceptions:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data RenewalDates;
input RenewalDt date9.;
format RenewalDt date9.;
cards;
28mar2017
29mar2017
30mar2017
31mar2017
01apr2017
;
run;

data AlertDates;
set RenewalDates;
format AlertDt date9.;
if RenewalDt not in ('29mar2017'd,'30mar2017'd,'31mar2017'd) then do;
	AlertDt=intnx('month',RenewalDt,-1,'s');
end;
else do;
	AlertDt=intnx('month',RenewalDt,0,'b');
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 22 Feb 2017 15:34:05 GMT</pubDate>
    <dc:creator>nehalsanghvi</dc:creator>
    <dc:date>2017-02-22T15:34:05Z</dc:date>
    <item>
      <title>Reverse engineer dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reverse-engineer-dates/m-p/334983#M75714</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So here's a question that's been bugging me for a while.&lt;/P&gt;
&lt;P&gt;Let's say we have a script (in our backoffice application) wich determines when to renew a policy. It has to do so on each day, a month in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Examples:&lt;/P&gt;
&lt;P&gt;on&amp;nbsp;1jan2017 it renews the policy's with renewaldate 1feb2017&lt;/P&gt;
&lt;P&gt;on 15mar2017 it renews the policy's with renewaldate 15apr2017&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BUT&lt;/P&gt;
&lt;P&gt;on 28feb2017 --&amp;gt; renewaldate 28mar2017&lt;/P&gt;
&lt;P&gt;on 1mar2017 --&amp;gt; renewaldates 29mar2017, 30mar2017, 31mar2017 and 1apr2017&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For our planning I want to reverse engineer this in a simple and effective way. I have the policy's and the renewaldates in 2017 and 2018. I can't figure out how to deal with the exceptions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First&amp;nbsp;I thought of INTNX and 'month' -1&amp;nbsp;and 'same day'. But that doesn't work. 29mar2017 turns into 28feb2017. I need it to be 1mar2017.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a way to reverse engineer this?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2017 15:13:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reverse-engineer-dates/m-p/334983#M75714</guid>
      <dc:creator>Matthijs</dc:creator>
      <dc:date>2017-02-22T15:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse engineer dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reverse-engineer-dates/m-p/334986#M75716</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data renewals;
input day_date yymmdd10.;
format day_date renewal yymmddd10.;
if day(day_date) = 1
then do renewal = intnx('month',intnx('month',day_date,-1,'end'),1,'same') + 1 to intnx('month',day_date,1,'same');
  output;
end;
else do;
  renewal = intnx('month',day_date,1,'same');
  output;
end;
cards;
2017-01-01
2017-03-15
2017-02-28
2017-03-01
2017-04-01
2017-05-01
run;
  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I added some additional "firsts" to illustrate the behaviour with 30 and 31-day months.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: changed the if condition to day(day_date) = 1. Original version was too complicated (unnecessarily).&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2017 15:28:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reverse-engineer-dates/m-p/334986#M75716</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-22T15:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse engineer dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reverse-engineer-dates/m-p/334989#M75718</link>
      <description>&lt;P&gt;Thank you very much! This is very helpfull.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2017 15:32:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reverse-engineer-dates/m-p/334989#M75718</guid>
      <dc:creator>Matthijs</dc:creator>
      <dc:date>2017-02-22T15:32:40Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse engineer dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reverse-engineer-dates/m-p/334990#M75719</link>
      <description>&lt;P&gt;Is this what you're looking for? If there is a rule for which days are always considered exceptions, then we could try programming that, but without that knowledge, I've hardcoded the exceptions:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data RenewalDates;
input RenewalDt date9.;
format RenewalDt date9.;
cards;
28mar2017
29mar2017
30mar2017
31mar2017
01apr2017
;
run;

data AlertDates;
set RenewalDates;
format AlertDt date9.;
if RenewalDt not in ('29mar2017'd,'30mar2017'd,'31mar2017'd) then do;
	AlertDt=intnx('month',RenewalDt,-1,'s');
end;
else do;
	AlertDt=intnx('month',RenewalDt,0,'b');
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Feb 2017 15:34:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reverse-engineer-dates/m-p/334990#M75719</guid>
      <dc:creator>nehalsanghvi</dc:creator>
      <dc:date>2017-02-22T15:34:05Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse engineer dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reverse-engineer-dates/m-p/334991#M75720</link>
      <description>&lt;P&gt;I use the term detect_date and renewaldate, where (generally) renewaldate= 1 month after detect_date, which the adjustments you explained.&amp;nbsp; Data set HAVE has a year of detect_date (01jan2001 to 31dec2001) and corresponding renewaldate's.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The data step creating WANT uses the series of renewaldates to generate detect_date_est, which matches the original detect_date:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have (keep=renew_date detect_date);
  do detect_date='01feb2001'd to '31dec2001'd;
    base_renewaldate=intnx('month',detect_date,1,'same');
    do renew_date=coalesce(lag(base_renewaldate)+1,base_renewaldate) to base_renewaldate; output; end;
  end;
  format detect_date base_renewaldate renew_date date9.;
run;
	
data want;
  set have;
  detect_date_est=intnx('month',renew_date,-1,'same');
  if day(detect_date_est)^=day(renew_date) then detect_date_est=detect_date_est+1;
  format detect_date_est date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Feb 2017 15:35:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reverse-engineer-dates/m-p/334991#M75720</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-22T15:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse engineer dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reverse-engineer-dates/m-p/334998#M75722</link>
      <description>&lt;P&gt;Thank you for your time and effort.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this solution I have to determine and 'name' the dates that are exceptions. In Kurts solution I don't have to do that. But again, thank you for taking the time!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2017 15:47:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reverse-engineer-dates/m-p/334998#M75722</guid>
      <dc:creator>Matthijs</dc:creator>
      <dc:date>2017-02-22T15:47:11Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse engineer dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reverse-engineer-dates/m-p/335001#M75724</link>
      <description>&lt;P&gt;Thank you for your time and effort.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run your code it skips a couple off detects_dates --&amp;gt; 31mar2001 for instance.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2017 15:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reverse-engineer-dates/m-p/335001#M75724</guid>
      <dc:creator>Matthijs</dc:creator>
      <dc:date>2017-02-22T15:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: Reverse engineer dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reverse-engineer-dates/m-p/335008#M75727</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/25406"&gt;@Matthijs&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you very much! This is very helpfull.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I guess your original problem came from the fact that you asked yourself 'How do I deal with the last of the month?'&lt;/P&gt;
&lt;P&gt;Instead I took the approach 'How do I deal with the first of a month', which is easier to detect and maybe handle.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It has often happened to me that approaching a problem from the "reverse side" led me to an easier solution. ie using last. instead of first. or vice-versa.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Feb 2017 16:04:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reverse-engineer-dates/m-p/335008#M75727</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-02-22T16:04:13Z</dc:date>
    </item>
  </channel>
</rss>

