<?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: Determining correct elapsed time using the SAS datepart and timepart in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Determining-correct-elapsed-time-using-the-SAS-datepart-and/m-p/680584#M205705</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/65907"&gt;@wlierman&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd be happy to help you.&amp;nbsp; Can you please set up sample data in the form of a sas data step (not csv - it's too much work for me)?&lt;/P&gt;</description>
    <pubDate>Tue, 01 Sep 2020 00:30:32 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2020-09-01T00:30:32Z</dc:date>
    <item>
      <title>Determining correct elapsed time using the SAS datepart and timepart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-correct-elapsed-time-using-the-SAS-datepart-and/m-p/680555#M205692</link>
      <description>&lt;P&gt;I am measuring the time between the creation_date (Created_on) and the time the person was reached (1st attempt; 2nd attempt; 3rd attempt).&amp;nbsp; The metric is that the time between the contact attempt (1st; 2nd; or 3rd) and the time the record was Created_on is within 24 hours.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the sequence should be Created_on and then measure the time from the contact attempt&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Time_1st_attempt - Created_on &amp;lt;= 24&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Time_2nd_attempt - Created_on &amp;lt;= 24&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Time_3rd_attempt - Created_on &amp;lt;= 24&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are times when the record was contacted successfully first and then the&amp;nbsp; record was Created_on in the record (so that is the negative time elapsed).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I forgot that for a few the dates are different. For example, one record was successfully contacted on the third attempt on 8/&lt;STRONG&gt;20&lt;/STRONG&gt;/2020 but the record was Created_On&amp;nbsp; 8/&lt;STRONG&gt;22&lt;/STRONG&gt;/2020.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can this 24 hours of the date be captured.&amp;nbsp; Usually the date of successful contact and Created record are the same date - but there are a few.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data ARIAS.Correct_hours (drop = First_Attempt Second_Attempt Third_Attempt Created_Date Person_ID Contact_ID Case_ID);&lt;BR /&gt;&amp;nbsp;&amp;nbsp; Format Hours_between_1stAttempt_Create 3.2; &lt;BR /&gt;&amp;nbsp;&amp;nbsp; Format Hours_between_2ndAttempt_Create 3.2;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; Format Hours_between_3rdAttempt_Create 3.2;&lt;BR /&gt;Set Arias.Time_Part;&lt;BR /&gt;If First_Attempt ne . and Second_Attempt eq . and Third_Attempt eq . then do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Hours_between_1stAttempt_Create = mod(/*24+*/(First_Attempt - Created_Date)/3600,24);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;Else If First_Attempt ne . and Second_Attempt ne . and Third_Attempt eq . then do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Hours_between_2ndAttempt_Create = mod(/*24+*/(Second_Attempt - Created_Date)/3600,24);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;Else If Third_Attempt ne . then do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Hours_between_3rdAttempt_Create = mod(/*24+*/(Third_Attempt - Created_Date)/3600,24);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have attached a small csv file that illustrates some of the problems in the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would appreciate your expertise in demonstrating the correct way to handle this data measurement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Walt Lierman&lt;/P&gt;</description>
      <pubDate>Mon, 31 Aug 2020 21:17:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-correct-elapsed-time-using-the-SAS-datepart-and/m-p/680555#M205692</guid>
      <dc:creator>wlierman</dc:creator>
      <dc:date>2020-08-31T21:17:58Z</dc:date>
    </item>
    <item>
      <title>Re: Determining correct elapsed time using the SAS datepart and timepart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-correct-elapsed-time-using-the-SAS-datepart-and/m-p/680584#M205705</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/65907"&gt;@wlierman&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd be happy to help you.&amp;nbsp; Can you please set up sample data in the form of a sas data step (not csv - it's too much work for me)?&lt;/P&gt;</description>
      <pubDate>Tue, 01 Sep 2020 00:30:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-correct-elapsed-time-using-the-SAS-datepart-and/m-p/680584#M205705</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-09-01T00:30:32Z</dc:date>
    </item>
    <item>
      <title>Re: Determining correct elapsed time using the SAS datepart and timepart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-correct-elapsed-time-using-the-SAS-datepart-and/m-p/680585#M205706</link>
      <description>I'll try to set somethig up.  It will be a small data set.</description>
      <pubDate>Tue, 01 Sep 2020 00:35:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-correct-elapsed-time-using-the-SAS-datepart-and/m-p/680585#M205706</guid>
      <dc:creator>wlierman</dc:creator>
      <dc:date>2020-09-01T00:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: Determining correct elapsed time using the SAS datepart and timepart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-correct-elapsed-time-using-the-SAS-datepart-and/m-p/680759#M205814</link>
      <description>I can't send the output dataset, since it is on a SAS server and I am remoting on Citrix.&lt;BR /&gt;&lt;BR /&gt;I appreciate your willingness to help, but I will repost the question.  I'll keep working a little to see if is possible to get the dataset via remote connection.&lt;BR /&gt;&lt;BR /&gt;Thank you.&lt;BR /&gt;&lt;BR /&gt;Walt Lierman</description>
      <pubDate>Tue, 01 Sep 2020 16:57:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-correct-elapsed-time-using-the-SAS-datepart-and/m-p/680759#M205814</guid>
      <dc:creator>wlierman</dc:creator>
      <dc:date>2020-09-01T16:57:53Z</dc:date>
    </item>
    <item>
      <title>Re: Determining correct elapsed time using the SAS datepart and timepart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-correct-elapsed-time-using-the-SAS-datepart-and/m-p/680779#M205820</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/65907"&gt;@wlierman&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I can't send the output dataset, since it is on a SAS server and I am remoting on Citrix.&lt;BR /&gt;&lt;BR /&gt;I appreciate your willingness to help, but I will repost the question. I'll keep working a little to see if is possible to get the dataset via remote connection.&lt;BR /&gt;&lt;BR /&gt;Thank you.&lt;BR /&gt;&lt;BR /&gt;Walt Lierman&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The request was just to send the data in a usable form instead of pasted into an attached file.&amp;nbsp; Fortunately this website lets you preview some attachments without downloading them.&amp;nbsp; So it looks like you have separate DATE and TIME values.&amp;nbsp; Just use them to make DATETIME values.&amp;nbsp; Then the difference between the two will be in seconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So here are some dates from a couple of rows that I pulled from the preview of your attachment.&amp;nbsp; So once I have the separate DATE and TIME values I can use the DHMS() function to make a DATETIME value.&amp;nbsp; Then simple subtraction will find the difference in seconds. Which can then be easily compared to the number of seconds in 24 hours.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input date1 time1 date2 time2 date3 time3 ;
  informat date: ddmmyy. time: time. ;
  datetime1=dhms(date1,0,0,time1);
  datetime2=dhms(date2,0,0,time2);
  datetime3=dhms(date3,0,0,time3);
  diff1 = datetime2 - datetime1;
  diff2 = datetime3 - datetime1;
  flag1 = (0 &amp;lt;= diff1 &amp;lt;= '24:00't);
  flag2 = (0 &amp;lt;= diff2 &amp;lt;= '24:00't);
  format date: yymmdd10. time: tod8. datetime: datetime19. ;
  format diff: time12.;
cards;
24/08/2020 9:52:00AM 24/08/2020 11:30:00AM . .
15/07/2020 9:38:00AM 16/07/2020 9:30:00AM 17/07/2020 2:45:00PM
;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;Obs        date1      time1        date2      time2        date3      time3

 1    2020-08-24   09:52:00   2020-08-24   11:30:00            .          .
 2    2020-07-15   09:38:00   2020-07-16   09:30:00   2020-07-17   14:45:00

Obs             datetime1              datetime2              datetime3

 1     24AUG2020:09:52:00     24AUG2020:11:30:00                      .
 2     15JUL2020:09:38:00     16JUL2020:09:30:00     17JUL2020:14:45:00

Obs          diff1           diff2    flag1    flag2

 1         1:38:00               .      1        0
 2        23:52:00        53:07:00      1        0&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Sep 2020 18:22:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-correct-elapsed-time-using-the-SAS-datepart-and/m-p/680779#M205820</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-09-01T18:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: Determining correct elapsed time using the SAS datepart and timepart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Determining-correct-elapsed-time-using-the-SAS-datepart-and/m-p/680791#M205829</link>
      <description>Tom,&lt;BR /&gt;&lt;BR /&gt;Thank you for your assistance with this.  The date and time part is challenging for me.  Thanks again.  Do you have any SAS / SUGI paper that you would recommend as a good&lt;BR /&gt;foundation?&lt;BR /&gt;Take care.&lt;BR /&gt;&lt;BR /&gt;Wlierman</description>
      <pubDate>Tue, 01 Sep 2020 18:54:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Determining-correct-elapsed-time-using-the-SAS-datepart-and/m-p/680791#M205829</guid>
      <dc:creator>wlierman</dc:creator>
      <dc:date>2020-09-01T18:54:28Z</dc:date>
    </item>
  </channel>
</rss>

