<?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: Months Difference between two dates with exact figures including decimals in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Months-Difference-between-two-dates-with-exact-figures-including/m-p/425211#M27396</link>
    <description>&lt;P&gt;How are you computing the expected difference in months?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried a few different guesses, but none of them matched what you are hoping for:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  input date1 : date9. date2 : date9.;

  days=date2-date1 ;

  months1=(date2-date1)/(365.25/12);
  months2=(date2-date1)/30.5 ;
  months3=(date2-date1)/30 ;

  format date1 date2 date9. ;

cards ;
20Oct2005 28Mar2008
11Mar2009 20Jun2011
23Feb2006 24Aug2006
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Returns:&lt;/P&gt;
&lt;PRE&gt;    date1        date2    days    months1    months2    months3

20OCT2005    28MAR2008     890    29.2402    29.1803    29.6667
11MAR2009    20JUN2011     831    27.3018    27.2459    27.7000
23FEB2006    24AUG2006     182     5.9795     5.9672     6.0667
&lt;/PRE&gt;</description>
    <pubDate>Fri, 05 Jan 2018 12:54:33 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2018-01-05T12:54:33Z</dc:date>
    <item>
      <title>Months Difference between two dates with exact figures including decimals</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Months-Difference-between-two-dates-with-exact-figures-including/m-p/425204#M27393</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to get the exact difference in months with decimals between two dates in SAS?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; want;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;input &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;date1=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;'01Jan2017'd&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;date2=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;'01Jan2018'd&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;months1=(date2-date1)/(&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;365.25&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;/&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;12&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;I have the above method, but not sure it's gives the accurate results...&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2018 12:16:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Months-Difference-between-two-dates-with-exact-figures-including/m-p/425204#M27393</guid>
      <dc:creator>Data_User</dc:creator>
      <dc:date>2018-01-05T12:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: Months Difference between two dates with exact figures including decimals</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Months-Difference-between-two-dates-with-exact-figures-including/m-p/425205#M27394</link>
      <description>&lt;P&gt;Expecting the results as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Date1&lt;/TD&gt;&lt;TD&gt;Date2&lt;/TD&gt;&lt;TD&gt;Difference in months&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;28-Mar-08&lt;/TD&gt;&lt;TD&gt;20-Oct-05&lt;/TD&gt;&lt;TD&gt;29.25806452&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;20-Jun-11&lt;/TD&gt;&lt;TD&gt;11-Mar-09&lt;/TD&gt;&lt;TD&gt;27.29032258&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;24-Aug-06&lt;/TD&gt;&lt;TD&gt;23-Feb-06&lt;/TD&gt;&lt;TD&gt;6.032258065&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 05 Jan 2018 12:28:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Months-Difference-between-two-dates-with-exact-figures-including/m-p/425205#M27394</guid>
      <dc:creator>Data_User</dc:creator>
      <dc:date>2018-01-05T12:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: Months Difference between two dates with exact figures including decimals</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Months-Difference-between-two-dates-with-exact-figures-including/m-p/425210#M27395</link>
      <description>&lt;P&gt;No. There is no strict definition for the duration of a month, so it makes no sense to calculate fractions of it.&lt;/P&gt;
&lt;P&gt;Your approximation is valid, but it's just that.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2018 12:53:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Months-Difference-between-two-dates-with-exact-figures-including/m-p/425210#M27395</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-05T12:53:57Z</dc:date>
    </item>
    <item>
      <title>Re: Months Difference between two dates with exact figures including decimals</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Months-Difference-between-two-dates-with-exact-figures-including/m-p/425211#M27396</link>
      <description>&lt;P&gt;How are you computing the expected difference in months?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried a few different guesses, but none of them matched what you are hoping for:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  input date1 : date9. date2 : date9.;

  days=date2-date1 ;

  months1=(date2-date1)/(365.25/12);
  months2=(date2-date1)/30.5 ;
  months3=(date2-date1)/30 ;

  format date1 date2 date9. ;

cards ;
20Oct2005 28Mar2008
11Mar2009 20Jun2011
23Feb2006 24Aug2006
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Returns:&lt;/P&gt;
&lt;PRE&gt;    date1        date2    days    months1    months2    months3

20OCT2005    28MAR2008     890    29.2402    29.1803    29.6667
11MAR2009    20JUN2011     831    27.3018    27.2459    27.7000
23FEB2006    24AUG2006     182     5.9795     5.9672     6.0667
&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Jan 2018 12:54:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Months-Difference-between-two-dates-with-exact-figures-including/m-p/425211#M27396</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2018-01-05T12:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: Months Difference between two dates with exact figures including decimals</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Months-Difference-between-two-dates-with-exact-figures-including/m-p/425214#M27397</link>
      <description>&lt;P&gt;There really isn't any such thing as a fixed unit of month, so you can't really have parts of a month without an approximation when comparing days difference.&amp;nbsp; However in your case given, the number of months between is:&lt;/P&gt;
&lt;PRE&gt;((year(date2) - year(date1)) * 12) + (month(date2)-month(date1))&lt;/PRE&gt;
&lt;P&gt;So first take number of years difference and each one is 12, then add the difference in months.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just hit post and then thought you could probably do the same far simpler using intnx('month',date1,date2);&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2018 13:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Months-Difference-between-two-dates-with-exact-figures-including/m-p/425214#M27397</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-05T13:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: Months Difference between two dates with exact figures including decimals</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Months-Difference-between-two-dates-with-exact-figures-including/m-p/425220#M27398</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  input date1 : date9. date2 : date9.;

  days=yrdif(date1,date2,'age')*12;
  format date1 date2 date9. ;

cards ;
20Oct2005 28Mar2008
11Mar2009 20Jun2011
23Feb2006 24Aug2006
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Jan 2018 13:41:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Months-Difference-between-two-dates-with-exact-figures-including/m-p/425220#M27398</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-01-05T13:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: Months Difference between two dates with exact figures including decimals</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Months-Difference-between-two-dates-with-exact-figures-including/m-p/425239#M27399</link>
      <description>&lt;P&gt;Thank you all!&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jan 2018 14:32:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Months-Difference-between-two-dates-with-exact-figures-including/m-p/425239#M27399</guid>
      <dc:creator>Data_User</dc:creator>
      <dc:date>2018-01-05T14:32:31Z</dc:date>
    </item>
    <item>
      <title>Re: Months Difference between two dates with exact figures including decimals</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Months-Difference-between-two-dates-with-exact-figures-including/m-p/425300#M27402</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/128492"&gt;@Data_User&lt;/a&gt; you are welcome.  If your question has been answered, please mark one of the answers as an accepted solution.</description>
      <pubDate>Fri, 05 Jan 2018 17:13:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Months-Difference-between-two-dates-with-exact-figures-including/m-p/425300#M27402</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2018-01-05T17:13:12Z</dc:date>
    </item>
  </channel>
</rss>

