<?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 in years in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229666#M41579</link>
    <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can we have the duration in Years Months and days?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Like 1 year 2 months and 3 days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 13 Oct 2015 09:23:36 GMT</pubDate>
    <dc:creator>KafeelBasha</dc:creator>
    <dc:date>2015-10-13T09:23:36Z</dc:date>
    <item>
      <title>Date in years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229405#M41517</link>
      <description>&lt;P&gt;In the below code I would like to see 'b' as years and days format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let b=9.19, then I would like to see this as 9 years 191 days format (years and days).&lt;/P&gt;&lt;P&gt;data dt;&lt;BR /&gt;a=today()-'01AUG2006'd;&lt;BR /&gt;b=a/365;&lt;BR /&gt;run;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me regarding this.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2015 07:14:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229405#M41517</guid>
      <dc:creator>KafeelBasha</dc:creator>
      <dc:date>2015-10-10T07:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: Date in years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229408#M41518</link>
      <description>Why are you starting a new thread?</description>
      <pubDate>Sat, 10 Oct 2015 08:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229408#M41518</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-10-10T08:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: Date in years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229414#M41519</link>
      <description>&lt;P&gt;I can understand, but is there a way we can get result as I mentioned year and days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there any format to be defined.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2015 08:57:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229414#M41519</guid>
      <dc:creator>KafeelBasha</dc:creator>
      <dc:date>2015-10-10T08:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: Date in years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229415#M41520</link>
      <description>&lt;P&gt;Use the floor() and mod() functions to get yeas and remaining days.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2015 09:26:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229415#M41520</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-10-10T09:26:39Z</dc:date>
    </item>
    <item>
      <title>Re: Date in years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229417#M41521</link>
      <description>&lt;P&gt;Leap years complicate things and&amp;nbsp;it depends on the start and end year to how many days and years a difference in days translates.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's why I believe you can't get this 100% right with a format applied on the number of days as there you've lost the information already which one had been the start year and which one the end year (to take leap years into account).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below code option should return what you're asking for taking leap years into account.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc fcmp outlib=work.funcs.years;
  function YearsAndDays(startdt, enddt) $;
    years=intck('year',startdt, enddt,'c');
    days=enddt-intnx('year',startdt,years,'s');
    length outval $20; 
    outval=cat(years,' years ',days,' days');
    return(outval);
  endsub;
run;

options cmplib=work.funcs;

data sample;
  var=YearsAndDays('01AUG2006'd, today());
  output;
  var=YearsAndDays('29Feb2012'd, '28Feb2013'd);
  output;
  var=YearsAndDays('28Feb2012'd, '28Feb2013'd);
  output;
  var=YearsAndDays('28Feb2011'd, '28Feb2012'd);
  output;
  var=YearsAndDays('28Feb2011'd, '29Feb2012'd);
  output;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Code above fixed as per&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats﻿&lt;/a&gt;&amp;nbsp;feedback.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2015 06:09:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229417#M41521</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-10-11T06:09:17Z</dc:date>
    </item>
    <item>
      <title>Re: Date in years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229643#M41577</link>
      <description>&lt;P&gt;Thanks a lot. It worked&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 06:09:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229643#M41577</guid>
      <dc:creator>KafeelBasha</dc:creator>
      <dc:date>2015-10-13T06:09:47Z</dc:date>
    </item>
    <item>
      <title>Re: Date in years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229666#M41579</link>
      <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can we have the duration in Years Months and days?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Like 1 year 2 months and 3 days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 09:23:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229666#M41579</guid>
      <dc:creator>KafeelBasha</dc:creator>
      <dc:date>2015-10-13T09:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: Date in years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229672#M41580</link>
      <description>&lt;P&gt;Sure you can. You just need to extend the function as posted a bit to calculate months and days instead of days only.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 11:03:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229672#M41580</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-10-13T11:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: Date in years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229673#M41581</link>
      <description>&lt;P&gt;Is it like,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;v1=YearsMonthsAndDays(d1,d2);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;d1 and d2 are two different dates.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 11:19:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229673#M41581</guid>
      <dc:creator>KafeelBasha</dc:creator>
      <dc:date>2015-10-13T11:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: Date in years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229677#M41583</link>
      <description>&lt;P&gt;No, it's extending the function as below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=work.funcs.years;
  function YearsAndDays(startdt, enddt) $;
    years=intck('year',startdt, enddt,'c');

    shift_dt=intnx('year',startdt,years,'s');
    months=intck('month',shift_dt, enddt,'c');

    shift_dt=intnx('month',shift_dt,months,'s');
    days=enddt-shift_dt;

    length outval $30; 
    outval=cat(years,' years ',months,' months ',days,' days');
    return(outval);
  endsub;
run;

options cmplib=work.funcs;

data sample;
  var=YearsAndDays('01AUG2006'd, today());
  output;
  var=YearsAndDays('29Feb2012'd, '28Feb2013'd);
  output;
  var=YearsAndDays('28Feb2012'd, '28Feb2013'd);
  output;
  var=YearsAndDays('28Feb2011'd, '28Feb2012'd);
  output;
  var=YearsAndDays('28Feb2011'd, '29Feb2012'd);
  output;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Question is: What is a year? Is 01jan2012 to 01jan2013 a year or a year and a day? Depends how you look at it I guess and if you interprete your end-date as exclusive or inclusive.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 11:45:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229677#M41583</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-10-13T11:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: Date in years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229850#M41634</link>
      <description>&lt;P&gt;Helpfull, thanks a lot.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Oct 2015 06:52:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-in-years/m-p/229850#M41634</guid>
      <dc:creator>KafeelBasha</dc:creator>
      <dc:date>2015-10-14T06:52:03Z</dc:date>
    </item>
  </channel>
</rss>

