<?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: How to convert no of days to years months days format. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-no-of-days-to-years-months-days-format/m-p/386895#M92717</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/156645"&gt;@Naveen45&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thankyou for your reply...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just want to know... Is there any fuction which can convert no of days to to yearsmothsdays format directly without writing that entire code..&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not that I know of. But thinking again brought me to a simpler solution, but you have to test if it works reliably across dates:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data diff;
bdate = '10sep2008'd;
edate = '14sep2010'd;
actdate = intck('days',bdate,edate);
format bdate edate actdate date9.;
dify = year(actdate) - 1960;
difm = month(actdate) - 1;
difd = day(actdate);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This uses the fact that the "zero" day for dates in SAS is 1960-01-01.&lt;/P&gt;</description>
    <pubDate>Thu, 10 Aug 2017 08:42:54 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-08-10T08:42:54Z</dc:date>
    <item>
      <title>How to convert no of days to years months days format.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-no-of-days-to-years-months-days-format/m-p/386885#M92712</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data Diff;&lt;/P&gt;&lt;P&gt;BDATE='10SEP2008'D;&lt;/P&gt;&lt;P&gt;EDATE='14SEP2010'DD;&lt;/P&gt;&lt;P&gt;ACTDATE=INTCK('DAYS', BDATE, EDATE);&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OUTPUT IS&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;BDATE&lt;/TD&gt;&lt;TD&gt;EDATE&lt;/TD&gt;&lt;TD&gt;ACTDATE&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;17785&lt;/TD&gt;&lt;TD&gt;18519&lt;/TD&gt;&lt;TD&gt;734&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to convert the above ACTDATE(734days) to 2years0months4days.&lt;/P&gt;&lt;P&gt;What is the code?&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2017 07:49:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-no-of-days-to-years-months-days-format/m-p/386885#M92712</guid>
      <dc:creator>Naveen45</dc:creator>
      <dc:date>2017-08-10T07:49:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert no of days to years months days format.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-no-of-days-to-years-months-days-format/m-p/386888#M92713</link>
      <description>&lt;P&gt;Use a succession of intck() and intnx() calls:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data diff;
bdate = '10sep2008'd;
edate = '14sep2010'd;
format bdate edate date9.;
actdate = intck('days',bdate,edate);
dify = int(intck('year',bdate,edate));
idate = intnx('year',bdate,dify,'s');
difm = int(intck('month',idate,edate));
idate = intnx('month',idate,difm,'s');
difd = intck('day',idate,edate);
length result $40;
result = strip(put(dify,3.)) !! 'years' !! strip(put(difm,2.)) !! 'months' !! strip(put(difd,2.)) !! 'days';
drop idate dify difm difd;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Aug 2017 08:00:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-no-of-days-to-years-months-days-format/m-p/386888#M92713</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-08-10T08:00:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert no of days to years months days format.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-no-of-days-to-years-months-days-format/m-p/386893#M92715</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thankyou for your reply...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just want to know... Is there any fuction which can convert no of days to to yearsmothsdays format directly without writing that entire code..&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2017 08:26:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-no-of-days-to-years-months-days-format/m-p/386893#M92715</guid>
      <dc:creator>Naveen45</dc:creator>
      <dc:date>2017-08-10T08:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert no of days to years months days format.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-no-of-days-to-years-months-days-format/m-p/386894#M92716</link>
      <description>We are close to the output but not exact...&lt;BR /&gt;when we change the bdate=24OCT1990 and edate=10AUG2017 we are getting wrong calculation as per the code..&lt;BR /&gt;can you fix it.</description>
      <pubDate>Thu, 10 Aug 2017 08:42:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-no-of-days-to-years-months-days-format/m-p/386894#M92716</guid>
      <dc:creator>Naveen45</dc:creator>
      <dc:date>2017-08-10T08:42:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert no of days to years months days format.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-no-of-days-to-years-months-days-format/m-p/386895#M92717</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/156645"&gt;@Naveen45&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thankyou for your reply...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just want to know... Is there any fuction which can convert no of days to to yearsmothsdays format directly without writing that entire code..&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not that I know of. But thinking again brought me to a simpler solution, but you have to test if it works reliably across dates:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data diff;
bdate = '10sep2008'd;
edate = '14sep2010'd;
actdate = intck('days',bdate,edate);
format bdate edate actdate date9.;
dify = year(actdate) - 1960;
difm = month(actdate) - 1;
difd = day(actdate);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This uses the fact that the "zero" day for dates in SAS is 1960-01-01.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2017 08:42:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-no-of-days-to-years-months-days-format/m-p/386895#M92717</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-08-10T08:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert no of days to years months days format.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-no-of-days-to-years-months-days-format/m-p/386898#M92719</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/156645"&gt;@Naveen45&lt;/a&gt; wrote:&lt;BR /&gt;We are close to the output but not exact...&lt;BR /&gt;when we change the bdate=24OCT1990 and edate=10AUG2017 we are getting wrong calculation as per the code..&lt;BR /&gt;can you fix it.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I made some small adjustments. Note that the day value will depend on what constitutes "months".&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data diff1;
bdate = '10sep2008'd;
edate = '14sep2010'd;
bdate = '24oct1990'd;
edate = '10aug2017'd;
format bdate edate date9.;
actdate = intck('days',bdate,edate);
dify = int(intck('year',bdate,edate,'c'));
idate = intnx('year',bdate,dify,'s');
difm = int(intck('month',idate,edate,'c'));
idate = intnx('month',idate,difm,'s');
difd = intck('day',idate,edate);
length result $40;
result = strip(put(dify,3.)) !! 'years' !! strip(put(difm,2.)) !! 'months' !! strip(put(difd,2.)) !! 'days';
drop idate dify difm difd;
run;

data diff2;
bdate = '24oct1990'd;
edate = '10aug2017'd;
bdate = '10sep2008'd;
edate = '14sep2010'd;
actdate = intck('days',bdate,edate);
format bdate edate actdate date9.;
dify = year(actdate) - 1960;
difm = month(actdate) - 1;
difd = day(actdate) - 1;
result = strip(put(dify,3.)) !! 'years' !! strip(put(difm,2.)) !! 'months' !! strip(put(difd,2.)) !! 'days';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Aug 2017 08:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-no-of-days-to-years-months-days-format/m-p/386898#M92719</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-08-10T08:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert no of days to years months days format.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-no-of-days-to-years-months-days-format/m-p/387069#M92765</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/156645"&gt;@Naveen45&lt;/a&gt; wrote:&lt;BR /&gt;We are close to the output but not exact...&lt;BR /&gt;when we change the bdate=24OCT1990 and edate=10AUG2017 we are getting wrong calculation as per the code..&lt;BR /&gt;can you fix it.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Define "months" in terms of your project. Since months may have 28, 29, 30 or 31 days on the calendar it is quite likely that calendar months any your "month" are not going to align. And actually I'm a bit cautious about "year" as the number of days changes for calendar years.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2017 15:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-no-of-days-to-years-months-days-format/m-p/387069#M92765</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-08-10T15:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert no of days to years months days format.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-no-of-days-to-years-months-days-format/m-p/562340#M157519</link>
      <description>&lt;P&gt;data demo2;&lt;BR /&gt;set demo;&lt;BR /&gt;days=intck('Day',bdate,svdate); /*how to conver this days into year*/&lt;BR /&gt;months=intck('Months',bdate,svdate);&lt;BR /&gt;year=intck('Years',bdate,svdate);&lt;BR /&gt;inyear=int(days/365);&amp;nbsp; /*this will convert days into year and&amp;nbsp; int which I have mention will eliminate decimal value and give year*/&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 16:27:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-no-of-days-to-years-months-days-format/m-p/562340#M157519</guid>
      <dc:creator>Ajayvit</dc:creator>
      <dc:date>2019-05-29T16:27:35Z</dc:date>
    </item>
  </channel>
</rss>

