<?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 date difference in months and days in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/calculate-date-difference-in-months-and-days/m-p/360271#M84781</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
infile cards expandtabs truncover;
input Date_1 : datetime32. Date_2 : yymmdd8.;
days=datepart(date_1)-date_2;
month=mod(yrdif(date_2,datepart(date_1),'act/act'),1)*12;
put days= month= ;
cards;
29Aug09:14:02:00	20090621
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 21 May 2017 03:45:50 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2017-05-21T03:45:50Z</dc:date>
    <item>
      <title>calculate date difference in months and days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-date-difference-in-months-and-days/m-p/360203#M84759</link>
      <description>&lt;P&gt;Hello all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with two dates Date_1 and Date_2. Date_1 has format datetime16. and informat 16. Date_2 has format $8. and informat $8. How do I calculate the date difference i.e Date_1- Date_2 in days and months.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Date_1&lt;/TD&gt;&lt;TD&gt;Date_2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;29Aug09:14:02:00&lt;/TD&gt;&lt;TD&gt;20090621&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Days&lt;/TD&gt;&lt;TD&gt;Months&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;69&lt;/TD&gt;&lt;TD&gt;2.26&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate your help,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 20 May 2017 18:06:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-date-difference-in-months-and-days/m-p/360203#M84759</guid>
      <dc:creator>Tomcaty</dc:creator>
      <dc:date>2017-05-20T18:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: calculate date difference in months and days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-date-difference-in-months-and-days/m-p/360204#M84760</link>
      <description>&lt;P&gt;A fun with functions type exercise.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Convert dates to same type - use &lt;FONT color="#0000FF"&gt;DATEPART()&lt;/FONT&gt; to get date portion of a DATETIME variable and use &lt;FONT color="#0000FF"&gt;INPUT()&lt;/FONT&gt; to convert the character variable to a date variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Use &lt;FONT color="#0000FF"&gt;INTCK()&lt;/FONT&gt; to calculate the differences - note the rules on how it's calculated and the last parameter (fourth) that defines the rules.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To convert the character variable you can use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date2_var = input(date_2, yymmdd8.);
format date2_var date9.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the link to the most recent documentation on functions:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#p0w6napahk6x0an0z2dzozh2ouzm.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#p0w6napahk6x0an0z2dzozh2ouzm.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have difficulty with the remaining functions, post what you've tried and what errors or incorrect output you receive.&lt;/P&gt;</description>
      <pubDate>Sat, 20 May 2017 18:51:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-date-difference-in-months-and-days/m-p/360204#M84760</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-20T18:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: calculate date difference in months and days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/calculate-date-difference-in-months-and-days/m-p/360271#M84781</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
infile cards expandtabs truncover;
input Date_1 : datetime32. Date_2 : yymmdd8.;
days=datepart(date_1)-date_2;
month=mod(yrdif(date_2,datepart(date_1),'act/act'),1)*12;
put days= month= ;
cards;
29Aug09:14:02:00	20090621
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 21 May 2017 03:45:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/calculate-date-difference-in-months-and-days/m-p/360271#M84781</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-05-21T03:45:50Z</dc:date>
    </item>
  </channel>
</rss>

