<?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: Time difference in defined work hours in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Time-difference-in-defined-work-hours/m-p/8587#M346</link>
    <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I send you one possible solution to your question.&lt;BR /&gt;
1) I have changed BOD and EOD format to TIME5.&lt;BR /&gt;
2) The calculation is do using DO sentence by days&lt;BR /&gt;
&lt;BR /&gt;
Best regards&lt;BR /&gt;
Jaroslav&lt;BR /&gt;
&lt;BR /&gt;
data test;&lt;BR /&gt;
infile datalines delimiter = ',';&lt;BR /&gt;
input INTIME : datetime19. OUTTIME : datetime19. BOD : TIME5. EOD : TIME5. Time_taken : $15.;&lt;BR /&gt;
format intime OUTTIME datetime19. BOD EOD TIME5.;&lt;BR /&gt;
cards;&lt;BR /&gt;
01OCT2009:08:00:00, 01OCT2009:18:00:00, 08:00, 18:00, 10 (+10)&lt;BR /&gt;
01OCT2009:08:00:00, 02OCT2009:16:00:00, 08:00, 18:00, 18 (10 +8)&lt;BR /&gt;
01OCT2009:08:00:00, 02OCT2009:16:00:00, 08:00, 20:00, 20 (12 + &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;&lt;BR /&gt;
01OCT2009:10:00:00, 03OCT2009:09:00:00, 08:00, 20:00, 23 (10+12+1)&lt;BR /&gt;
;&lt;BR /&gt;
run; &lt;BR /&gt;
&lt;BR /&gt;
DATA TEST(DROP=DAY);&lt;BR /&gt;
 FORMAT DIFERENCE TIME5.;&lt;BR /&gt;
 RETAIN DIFERENCE;&lt;BR /&gt;
 SET TEST;&lt;BR /&gt;
 DO DAY=DATEPART(INTIME) TO DATEPART(OUTTIME);&lt;BR /&gt;
  IF DAY=DATEPART(INTIME) THEN DIFERENCE=0;&lt;BR /&gt;
  DIFERENCE=DIFERENCE+MIN(OUTTIME,DHMS(DAY,0,0,EOD))-MAX(INTIME,DHMS(DAY,0,0,BOD));&lt;BR /&gt;
  IF DAY=DATEPART(OUTTIME) THEN OUTPUT;&lt;BR /&gt;
 END;&lt;BR /&gt;
RUN;</description>
    <pubDate>Wed, 28 Oct 2009 09:43:38 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-10-28T09:43:38Z</dc:date>
    <item>
      <title>Time difference in defined work hours</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-difference-in-defined-work-hours/m-p/8586#M345</link>
      <description>Guys,&lt;BR /&gt;
I have a dataset in the below format which has Intime, Outime, the Begin time of a working day and the End time of working day.&lt;BR /&gt;
I have to calculate the difference between intime and outtime in hours (Time_taken) but the difference has to be on the basis of the BOD and EOD.&lt;BR /&gt;
Ex: In the second case you can see that time taken is 10 hours in the first day and 8 hours in the second day. hence total time taken is 18 hours.&lt;BR /&gt;
If somebody has worked on something like this then kindly help.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data test;&lt;BR /&gt;
infile datalines delimiter = ',';&lt;BR /&gt;
input INTIME : datetime19. OUTTIME : datetime19. BOD : $5. EOD : $5. Time_taken : $15.;&lt;BR /&gt;
format intime : datetime19. OUTTIME : datetime19.;&lt;BR /&gt;
cards;&lt;BR /&gt;
01OCT2009:08:00:00, 01OCT2009:18:00:00, 08:00, 18:00, 10 (+10)&lt;BR /&gt;
01OCT2009:08:00:00, 02OCT2009:16:00:00, 08:00, 18:00, 18 (10 +8)&lt;BR /&gt;
01OCT2009:08:00:00, 02OCT2009:16:00:00, 08:00, 20:00, 20 (12 + &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;&lt;BR /&gt;
01OCT2009:10:00:00, 03OCT2009:09:00:00, 08:00, 20:00, 23 (10+12+1) &lt;BR /&gt;
;&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 28 Oct 2009 06:48:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-difference-in-defined-work-hours/m-p/8586#M345</guid>
      <dc:creator>NN</dc:creator>
      <dc:date>2009-10-28T06:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: Time difference in defined work hours</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-difference-in-defined-work-hours/m-p/8587#M346</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I send you one possible solution to your question.&lt;BR /&gt;
1) I have changed BOD and EOD format to TIME5.&lt;BR /&gt;
2) The calculation is do using DO sentence by days&lt;BR /&gt;
&lt;BR /&gt;
Best regards&lt;BR /&gt;
Jaroslav&lt;BR /&gt;
&lt;BR /&gt;
data test;&lt;BR /&gt;
infile datalines delimiter = ',';&lt;BR /&gt;
input INTIME : datetime19. OUTTIME : datetime19. BOD : TIME5. EOD : TIME5. Time_taken : $15.;&lt;BR /&gt;
format intime OUTTIME datetime19. BOD EOD TIME5.;&lt;BR /&gt;
cards;&lt;BR /&gt;
01OCT2009:08:00:00, 01OCT2009:18:00:00, 08:00, 18:00, 10 (+10)&lt;BR /&gt;
01OCT2009:08:00:00, 02OCT2009:16:00:00, 08:00, 18:00, 18 (10 +8)&lt;BR /&gt;
01OCT2009:08:00:00, 02OCT2009:16:00:00, 08:00, 20:00, 20 (12 + &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt;&lt;BR /&gt;
01OCT2009:10:00:00, 03OCT2009:09:00:00, 08:00, 20:00, 23 (10+12+1)&lt;BR /&gt;
;&lt;BR /&gt;
run; &lt;BR /&gt;
&lt;BR /&gt;
DATA TEST(DROP=DAY);&lt;BR /&gt;
 FORMAT DIFERENCE TIME5.;&lt;BR /&gt;
 RETAIN DIFERENCE;&lt;BR /&gt;
 SET TEST;&lt;BR /&gt;
 DO DAY=DATEPART(INTIME) TO DATEPART(OUTTIME);&lt;BR /&gt;
  IF DAY=DATEPART(INTIME) THEN DIFERENCE=0;&lt;BR /&gt;
  DIFERENCE=DIFERENCE+MIN(OUTTIME,DHMS(DAY,0,0,EOD))-MAX(INTIME,DHMS(DAY,0,0,BOD));&lt;BR /&gt;
  IF DAY=DATEPART(OUTTIME) THEN OUTPUT;&lt;BR /&gt;
 END;&lt;BR /&gt;
RUN;</description>
      <pubDate>Wed, 28 Oct 2009 09:43:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-difference-in-defined-work-hours/m-p/8587#M346</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-10-28T09:43:38Z</dc:date>
    </item>
    <item>
      <title>Re: Time difference in defined work hours</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-difference-in-defined-work-hours/m-p/8588#M347</link>
      <description>Jaroslav Thanks a lot This works just fine</description>
      <pubDate>Wed, 28 Oct 2009 10:19:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-difference-in-defined-work-hours/m-p/8588#M347</guid>
      <dc:creator>NN</dc:creator>
      <dc:date>2009-10-28T10:19:05Z</dc:date>
    </item>
  </channel>
</rss>

