<?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: Get future date from an existing date with conditionally adding months or years to the existing in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Get-future-date-from-an-existing-date-with-conditionally-adding/m-p/874187#M38810</link>
    <description>&lt;P&gt;So convert your dates into dates and convert your interval into two variables. One with the number and one with the type of interval.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input start_dt :date. interval_value interval_type $ ;
  format start_dt date9.;
cards;
16DEC2005 3 year
14JUN2021 1 year
29AUG2019 2 year
12DEC2013 1 month
10JAN2019 3 year
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Sounds like you want to increment until the end date is on or after today.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  do offset=0 by interval_value until(end_dt &amp;gt;= today());
    end_dt=intnx(interval_type,start_dt,offset,'same');
  end;
  format end_dt date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;                    interval_    interval_
Obs     start_dt      value        type       offset       end_dt

 1     16DEC2005        3          year          18     16DEC2023
 2     14JUN2021        1          year           2     14JUN2023
 3     29AUG2019        2          year           4     29AUG2023
 4     12DEC2013        1          month        113     12MAY2023
 5     10JAN2019        3          year           6     10JAN2025

&lt;/PRE&gt;</description>
    <pubDate>Fri, 05 May 2023 18:20:03 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-05-05T18:20:03Z</dc:date>
    <item>
      <title>Get future date from an existing date with conditionally adding months or years to the existing date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Get-future-date-from-an-existing-date-with-conditionally-adding/m-p/874177#M38805</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on a sample data set below and need to get the missing end_dt column from the start_dt,asked_term,renew_term&lt;/P&gt;&lt;P&gt;How to caluclate:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Iteration 1: Start_dt + renew_term&amp;nbsp;&lt;/P&gt;&lt;P&gt;If iteration 1 result is greater than today() then end as END_DT&lt;/P&gt;&lt;P&gt;ELSE&amp;nbsp;&lt;/P&gt;&lt;P&gt;Add asked_term in a loop until&amp;nbsp; the output date is greater than today()&lt;/P&gt;&lt;P&gt;Calculation sample:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="KranthiK_J_0-1683305693269.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83655iB6744B2C439BE345/image-size/medium?v=v2&amp;amp;px=400" role="button" title="KranthiK_J_0-1683305693269.png" alt="KranthiK_J_0-1683305693269.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset:&lt;/P&gt;&lt;PRE&gt;start_dt	       end_dt	   asked_term	                     renew_term                      
16DEC2005:00:00:00	.	   3 year                        	1 year                        
14JUN2021:00:00:00	.	   1 year                        	1 year                                                                      
29AUG2019:00:00:00	.	   2 year                        	1 year                                               
12DEC2013:00:00:00	.	   Monthly                       	1 year                                              
10JAN2019:00:00:00	.	   3 year                        	4 year                        &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 16:55:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Get-future-date-from-an-existing-date-with-conditionally-adding/m-p/874177#M38805</guid>
      <dc:creator>KranthiK_J</dc:creator>
      <dc:date>2023-05-05T16:55:32Z</dc:date>
    </item>
    <item>
      <title>Re: Get future date from an existing date with conditionally adding months or years to the existing</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Get-future-date-from-an-existing-date-with-conditionally-adding/m-p/874182#M38807</link>
      <description>&lt;P&gt;Your picture shows date values, not that I understand what you are trying to show with the picture.&lt;/P&gt;
&lt;P&gt;Your "dataset' has datetime value. Which is it? Date or Datetime? If all of the times are 00:00:00 why bother with time?&lt;/P&gt;
&lt;P&gt;What variable in your data holds 'iteration'?&lt;/P&gt;
&lt;P&gt;I think you need to show us what the expected result of this operation looks like as I am pretty sure I don't understand what your are asking for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I might make some guesses for something like 3 years but "monthly" doesn't have any number of times associated with it. Does that mean to create dates (or datetimes) until you exceed the values that SAS wants to handle? Note that for dates that would mean around year 20,000 not than any of the date formats will display past year 9999...&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 17:37:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Get-future-date-from-an-existing-date-with-conditionally-adding/m-p/874182#M38807</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-05T17:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: Get future date from an existing date with conditionally adding months or years to the existing</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Get-future-date-from-an-existing-date-with-conditionally-adding/m-p/874184#M38809</link>
      <description>&lt;P&gt;The values i have in the data set is date time, we need to convert the datetime to date before we do our calculation. As you mentioned, they are all 00:00:00 which is why we dont need the time just convert the datetime to date and then do our calculation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is no variable that holds the iteration, i was just giving an example how i need the calculation to be done to get the end_date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;And the monthly is just one month. Instead of 3 years or 1 year from the second iteration we have to add 1 month everytime until the end_date is greater than today.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 17:50:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Get-future-date-from-an-existing-date-with-conditionally-adding/m-p/874184#M38809</guid>
      <dc:creator>KranthiK_J</dc:creator>
      <dc:date>2023-05-05T17:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: Get future date from an existing date with conditionally adding months or years to the existing</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Get-future-date-from-an-existing-date-with-conditionally-adding/m-p/874187#M38810</link>
      <description>&lt;P&gt;So convert your dates into dates and convert your interval into two variables. One with the number and one with the type of interval.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input start_dt :date. interval_value interval_type $ ;
  format start_dt date9.;
cards;
16DEC2005 3 year
14JUN2021 1 year
29AUG2019 2 year
12DEC2013 1 month
10JAN2019 3 year
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Sounds like you want to increment until the end date is on or after today.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  do offset=0 by interval_value until(end_dt &amp;gt;= today());
    end_dt=intnx(interval_type,start_dt,offset,'same');
  end;
  format end_dt date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;                    interval_    interval_
Obs     start_dt      value        type       offset       end_dt

 1     16DEC2005        3          year          18     16DEC2023
 2     14JUN2021        1          year           2     14JUN2023
 3     29AUG2019        2          year           4     29AUG2023
 4     12DEC2013        1          month        113     12MAY2023
 5     10JAN2019        3          year           6     10JAN2025

&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 May 2023 18:20:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Get-future-date-from-an-existing-date-with-conditionally-adding/m-p/874187#M38810</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-05T18:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: Get future date from an existing date with conditionally adding months or years to the existing</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Get-future-date-from-an-existing-date-with-conditionally-adding/m-p/874364#M38813</link>
      <description>&lt;P&gt;Thanks for the solution tom. However, here you are just considering the &lt;STRONG&gt;'asked_term'&amp;nbsp;&lt;/STRONG&gt; as the interval value and interval type.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But what i need is first add the &lt;STRONG&gt;'Renew_term'&lt;/STRONG&gt; only once. When added, if the END_DATE doesnt increment to more than today, then only i need to consider the 'Asked_term' and offset the same value until i get the desired date (which is more than today).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here when just considered the asked_term the end_date would not be right for all the cases.&lt;/P&gt;</description>
      <pubDate>Sun, 07 May 2023 22:12:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Get-future-date-from-an-existing-date-with-conditionally-adding/m-p/874364#M38813</guid>
      <dc:creator>KranthiK_J</dc:creator>
      <dc:date>2023-05-07T22:12:54Z</dc:date>
    </item>
    <item>
      <title>Re: Get future date from an existing date with conditionally adding months or years to the existing</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Get-future-date-from-an-existing-date-with-conditionally-adding/m-p/874365#M38814</link>
      <description>consider the below example:&lt;BR /&gt;Start_dt:10MAR2023:00:00:00 Asked_Term: 3 year Renew_term: 1 year&lt;BR /&gt;&lt;BR /&gt;In this case the expected result is End_dt: 10MAR2024&lt;BR /&gt;&lt;BR /&gt;Cause always first add renew_term once if the condition didn't meet then go to the asked term and add the asked_term value until it meets the condition</description>
      <pubDate>Sun, 07 May 2023 22:18:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Get-future-date-from-an-existing-date-with-conditionally-adding/m-p/874365#M38814</guid>
      <dc:creator>KranthiK_J</dc:creator>
      <dc:date>2023-05-07T22:18:43Z</dc:date>
    </item>
    <item>
      <title>Re: Get future date from an existing date with conditionally adding months or years to the existing</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Get-future-date-from-an-existing-date-with-conditionally-adding/m-p/874367#M38815</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/440383"&gt;@KranthiK_J&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for the solution tom. However, here you are just considering the &lt;STRONG&gt;'asked_term'&amp;nbsp;&lt;/STRONG&gt; as the interval value and interval type.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But what i need is first add the &lt;STRONG&gt;'Renew_term'&lt;/STRONG&gt; only once. When added, if the END_DATE doesnt increment to more than today, then only i need to consider the 'Asked_term' and offset the same value until i get the desired date (which is more than today).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here when just considered the asked_term the end_date would not be right for all the cases.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Try it yourself.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sketch:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Use the "renew term" variables to derive END from START.&lt;/LI&gt;
&lt;LI&gt;Change the DO loop to use WHILE() instead of UNTIL() so it is possible it runs zero times.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;If it does not work then show what you did and explain how it did not do what you want.&lt;/P&gt;</description>
      <pubDate>Sun, 07 May 2023 23:11:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Get-future-date-from-an-existing-date-with-conditionally-adding/m-p/874367#M38815</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-05-07T23:11:19Z</dc:date>
    </item>
  </channel>
</rss>

