<?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: Calculate the date using (duration(varchar)) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculate-the-date-using-duration-varchar/m-p/673551#M202650</link>
    <description>1. Use COUNTW() to find the number of terms.This is used to control the loop ie first row has years and days whereas the last has only weeks.&lt;BR /&gt;2. Use SCAN to extract the components within a loop. &lt;BR /&gt;3. Pass parameters to INTNX() -  you need to likely remove the s from weeks etc. &lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;x= countw(duration);&lt;BR /&gt;new_date = diag_date;&lt;BR /&gt;do i=1 to x by 2;&lt;BR /&gt;increment = scan(duration, i);&lt;BR /&gt;interval = scan(duration, i+1);&lt;BR /&gt;new_date = intnx(increment, new_date, duration, 's');&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;This is only an outline. Untested. You likely need to verify your increments come in correctly but I think the solution as outlined would work. &lt;BR /&gt;&lt;BR /&gt;I'd also explore a custom informat but that seems like a lot more work.</description>
    <pubDate>Thu, 30 Jul 2020 19:47:46 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-07-30T19:47:46Z</dc:date>
    <item>
      <title>Calculate the date using (duration(varchar))</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-the-date-using-duration-varchar/m-p/673546#M202646</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I need to calculate the Record_date column using Duration and Diagnosis_Date.&lt;/P&gt;
&lt;P&gt;The Duration column in different formats. I simply updated the Record_date column as manual calculation&lt;/P&gt;
&lt;P&gt;but suggest me to find the accurate date in the Record_date column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="501px"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="218px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="129px" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="153px" height="30px"&gt;&lt;STRONG&gt;OUTPUT&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="218px" height="30px"&gt;Duration&lt;/TD&gt;
&lt;TD width="129px" height="30px"&gt;Diag_Date&lt;/TD&gt;
&lt;TD width="153px" height="30px"&gt;Record_Date&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="218px" height="57px"&gt;4 Years 2 Days&amp;nbsp;&lt;/TD&gt;
&lt;TD width="129px" height="57px"&gt;23-06-2016&lt;/TD&gt;
&lt;TD width="153px" height="57px"&gt;21-06-2012&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="218px" height="57px"&gt;12 Years&amp;nbsp;&lt;/TD&gt;
&lt;TD width="129px" height="57px"&gt;27-06-2008&lt;/TD&gt;
&lt;TD width="153px" height="57px"&gt;27-06-1996&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="218px" height="57px"&gt;5 Years 1 Month 3 Days&amp;nbsp;&lt;/TD&gt;
&lt;TD width="129px" height="57px"&gt;14-05-2015&lt;/TD&gt;
&lt;TD width="153px" height="57px"&gt;11-04-2010&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="218px" height="57px"&gt;3 Month 17 Days&amp;nbsp;&lt;/TD&gt;
&lt;TD width="129px" height="57px"&gt;09-03-2020&lt;/TD&gt;
&lt;TD width="153px" height="57px"&gt;21-11-2019&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="218px" height="57px"&gt;5 Days&amp;nbsp;&lt;/TD&gt;
&lt;TD width="129px" height="57px"&gt;18-03-2020&lt;/TD&gt;
&lt;TD width="153px" height="57px"&gt;13-03-2020&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="218px" height="57px"&gt;1 MONTH&lt;/TD&gt;
&lt;TD width="129px" height="57px"&gt;07-05-2020&lt;/TD&gt;
&lt;TD width="153px" height="57px"&gt;07-04-2020&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="218px" height="57px"&gt;3 Weeks&lt;/TD&gt;
&lt;TD width="129px" height="57px"&gt;18-03-2019&lt;/TD&gt;
&lt;TD width="153px" height="57px"&gt;25-02-2019&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jul 2020 19:31:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-the-date-using-duration-varchar/m-p/673546#M202646</guid>
      <dc:creator>Sathish_jammy</dc:creator>
      <dc:date>2020-07-30T19:31:42Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the date using (duration(varchar))</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-the-date-using-duration-varchar/m-p/673551#M202650</link>
      <description>1. Use COUNTW() to find the number of terms.This is used to control the loop ie first row has years and days whereas the last has only weeks.&lt;BR /&gt;2. Use SCAN to extract the components within a loop. &lt;BR /&gt;3. Pass parameters to INTNX() -  you need to likely remove the s from weeks etc. &lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;x= countw(duration);&lt;BR /&gt;new_date = diag_date;&lt;BR /&gt;do i=1 to x by 2;&lt;BR /&gt;increment = scan(duration, i);&lt;BR /&gt;interval = scan(duration, i+1);&lt;BR /&gt;new_date = intnx(increment, new_date, duration, 's');&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;This is only an outline. Untested. You likely need to verify your increments come in correctly but I think the solution as outlined would work. &lt;BR /&gt;&lt;BR /&gt;I'd also explore a custom informat but that seems like a lot more work.</description>
      <pubDate>Thu, 30 Jul 2020 19:47:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-the-date-using-duration-varchar/m-p/673551#M202650</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-07-30T19:47:46Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate the date using (duration(varchar))</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculate-the-date-using-duration-varchar/m-p/673623#M202690</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215282"&gt;@Sathish_jammy&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your sample observation with&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; duration=3 month 17 days,&amp;nbsp; and diag_date=09-03-2020&lt;/P&gt;
&lt;P&gt;is interesting&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have the &lt;EM&gt;&lt;STRONG&gt;expected record_date=21-11-2019&lt;/STRONG&gt;&lt;/EM&gt;, which is &lt;EM&gt;&lt;STRONG&gt;not&lt;/STRONG&gt;&lt;/EM&gt; the result SAS will generate if you&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;First, subtract 3 months from 09-03-2020,&amp;nbsp;&amp;nbsp;&amp;nbsp; yielding&amp;nbsp; 09-12-2019,&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRIKE&gt;09-12-2020&lt;/STRIKE&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; followed by&lt;/LI&gt;
&lt;LI&gt;Subtract 17 days from&amp;nbsp;&amp;nbsp; 09-12-2019,&amp;nbsp;&amp;nbsp;&amp;nbsp; yielding&amp;nbsp; &lt;EM&gt;&lt;STRONG&gt;record_date= 22-11-2019&lt;/STRONG&gt;&lt;/EM&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Yet if you went in the other direction, starting with record_date=22-11-2019, &lt;EM&gt;&lt;STRONG&gt;add&lt;/STRONG&gt;&lt;/EM&gt; three months, then &lt;EM&gt;&lt;STRONG&gt;add&lt;/STRONG&gt;&lt;/EM&gt; 17 days you would get diag_date=09-03-2020, as per your sample.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will have to decide which date is the reference point.&amp;nbsp; Given the text in duration ("x years y months z days") the actual number of days between record_date and diag_date is not symmetrical.&amp;nbsp;&amp;nbsp; BTW, you would still have asymmetry even if you reversed the elements in duration (z days y months x years).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If, since most people think of duration as going forward, you want to make record_date as the reference point, even though it is derived from diag_date, you'll have to do a two-stage process:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Calculate a provisional record_date first, going backwards from diag_date.&lt;/LI&gt;
&lt;LI&gt;Then see if going forward from the provisional record_date yields diag_date.&amp;nbsp; If it doesn't, adjust the provisional record_date accordingly.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Fri, 31 Jul 2020 05:53:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculate-the-date-using-duration-varchar/m-p/673623#M202690</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-07-31T05:53:38Z</dc:date>
    </item>
  </channel>
</rss>

