<?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 How to calculate datetime difference between two date values in minutes and hours in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-datetime-difference-between-two-date-values-in/m-p/234426#M54936</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="messagebodydisplay_0" class="lia-message-body"&gt;
&lt;DIV class="lia-message-body-content"&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I need help (SAS code) in calculating difference in minutes and hours for datetime variables. I have attached a copy of my data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here I have several Reg_Nos and the corresponding culture_dates (datetime). Some of the Reg_nos have multiple culture_date which are in different row compared to the first culture_date for that Reg_no (eg. I have highlighted in red).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to find the difference in minutes and hours from the first culture_date to the next cultre_date if a Reg_No has more than one culture_date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the help!&lt;/P&gt;
&lt;P&gt;Satish&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
    <pubDate>Thu, 12 Nov 2015 18:09:43 GMT</pubDate>
    <dc:creator>smunigala</dc:creator>
    <dc:date>2015-11-12T18:09:43Z</dc:date>
    <item>
      <title>How to calculate datetime difference between two date values in minutes and hours</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-datetime-difference-between-two-date-values-in/m-p/234426#M54936</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="messagebodydisplay_0" class="lia-message-body"&gt;
&lt;DIV class="lia-message-body-content"&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I need help (SAS code) in calculating difference in minutes and hours for datetime variables. I have attached a copy of my data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here I have several Reg_Nos and the corresponding culture_dates (datetime). Some of the Reg_nos have multiple culture_date which are in different row compared to the first culture_date for that Reg_no (eg. I have highlighted in red).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to find the difference in minutes and hours from the first culture_date to the next cultre_date if a Reg_No has more than one culture_date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the help!&lt;/P&gt;
&lt;P&gt;Satish&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 12 Nov 2015 18:09:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-datetime-difference-between-two-date-values-in/m-p/234426#M54936</guid>
      <dc:creator>smunigala</dc:creator>
      <dc:date>2015-11-12T18:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate datetime difference between two date values in minutes and hours</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-datetime-difference-between-two-date-values-in/m-p/234444#M54939</link>
      <description>&lt;OL&gt;
&lt;LI&gt;Sort by Reg_no and Culture Date&lt;/LI&gt;
&lt;LI&gt;In the sorted data set, compute the difference between the current culture date and the previous culture date (use the LAG function)&lt;/LI&gt;
&lt;LI&gt;Compute the number of minutes and hours from the result in step 2.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: you'd want to not count the cases where the current reg_no and the previous reg_no don't match, again LAG can help you determine this.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2015 19:02:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-datetime-difference-between-two-date-values-in/m-p/234444#M54939</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-11-12T19:02:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate datetime difference between two date values in minutes and hours</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-datetime-difference-between-two-date-values-in/m-p/234556#M54957</link>
      <description>&lt;P&gt;Here's a sample code using retain instead of lag.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data reg_no(drop=day row);&lt;BR /&gt;do reg_no=1 to 10;&lt;BR /&gt; do row = 1 to reg_no;&lt;BR /&gt; day=mdy(12,31,2014);&lt;BR /&gt; culture_date= DHMS(day+row,reg_no+row*row,reg_no,0) ;&lt;BR /&gt; format culture_date datetime.;&lt;BR /&gt; format day ddmmyy.;&lt;BR /&gt; output;&lt;BR /&gt; end;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data reg_no2(drop=lastdate);&lt;BR /&gt; set reg_no;&lt;BR /&gt; retain lastdate firstdate;&lt;BR /&gt; format delay time. ;&lt;BR /&gt; format delay_since_first time. ;&lt;BR /&gt; by reg_no;&lt;BR /&gt; if first.reg_no then &lt;BR /&gt; do;&lt;BR /&gt; lastdate=culture_date;&lt;BR /&gt; firstdate=culture_date;&lt;BR /&gt; end;&lt;BR /&gt; else do;&lt;BR /&gt; delay= culture_date - lastdate;&lt;BR /&gt; lastdate= culture_date;&lt;BR /&gt; delay_since_first= culture_date - firstdate;&lt;BR /&gt; end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2015 09:14:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-datetime-difference-between-two-date-values-in/m-p/234556#M54957</guid>
      <dc:creator>morglum</dc:creator>
      <dc:date>2015-11-13T09:14:25Z</dc:date>
    </item>
  </channel>
</rss>

