<?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 between timestamps during business hours in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/time-difference-between-timestamps-during-business-hours/m-p/203363#M37884</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sounds like a "&lt;A href="http://support.sas.com/documentation/cdl/en/etsug/63939/HTML/default/viewer.htm#etsug_intervals_sect008.htm"&gt;Custom Time Interval&lt;/A&gt;" is what you need, perhaps you can use the &lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p12v9lpx7rlthin1cnpd320l3mj3.htm"&gt;"Holiday"&lt;/A&gt; function to help you determine other days to exclude.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 17 Mar 2015 16:25:11 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2015-03-17T16:25:11Z</dc:date>
    <item>
      <title>time difference between timestamps during business hours</title>
      <link>https://communities.sas.com/t5/SAS-Programming/time-difference-between-timestamps-during-business-hours/m-p/203361#M37882</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to calculate time difference between two timestamps(datetime) during business hours only(8:00AM to 6:00PM), excluding public holidays and week ends. public holidays list is saved in a dataset or as a list in a macro variable value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for example, starting time is 30DEC2014:15:30:00 and ending time is 05JAN2015:09:52:00.&lt;/P&gt;&lt;P&gt;In this case 01Jan2015 is public holiday and 3rd &amp;amp; 4th Jan15 are week end. Therefore, time difference I want to calculate is&lt;/P&gt;&lt;P&gt;2:30(on 30th Dec14) + 10:00(on 31st Dec14) + 10:00(on 2nd Jan15)&amp;nbsp; + 1:52(on 5th Jan15) =24:22&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, starting and/or ending time may be earlier than 8:00AM and/or later than 6:00PM. Still, I am only interested in time duration&lt;/P&gt;&lt;P&gt;during business hours.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can any one help me to implement an efficient logic for the time calculation please.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks inadvance,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hari&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Mar 2015 15:30:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/time-difference-between-timestamps-during-business-hours/m-p/203361#M37882</guid>
      <dc:creator>harithalavu</dc:creator>
      <dc:date>2015-03-17T15:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: time difference between timestamps during business hours</title>
      <link>https://communities.sas.com/t5/SAS-Programming/time-difference-between-timestamps-during-business-hours/m-p/203362#M37883</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is a way, its a bit messy and not optimised, but its only to show you a method.&amp;nbsp; First, I wouldn't recommend putting the holidays in a macro parameter, that will just cause you headaches.&amp;nbsp; I would expand the time by dates first, then remove holidays.&amp;nbsp; Then have a datastep with a calculation of time, and retain that count through the dataset ending up with last row having total.&amp;nbsp; As mentioned this was done quickly to give the idea.&lt;/P&gt;&lt;P&gt;data phols;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format hol_date date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; hol_date="01JAN2015"d; output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Expand dates */&lt;/P&gt;&lt;P&gt;data inter;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format start_dt end_dt datetime. datepart date9.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; start_dt="30dec2014T15:30:00"dt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end_dt="05JAN2015T09:52:00"dt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=datepart(start_dt) to datepart(end_dt);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; datepart=i;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Remove holidays */&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; delete from INTER where exists(select HOL_DATE from PHOLS where HOL_DATE=DATEPART);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set inter end=last;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format tot_time time5.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain tot_time;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if _n_=1 then do;&amp;nbsp; /* These are where times come in */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if timepart(start_dt) &amp;lt; "08:00"t then tot_time="10:00"t;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else tot_time="18:00"t - timepart(start_dt);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if last then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if timepart(end_dt) &amp;gt; "18:00"t then tot_time=tot_time+"10:00"t;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else tot_time=tot_time + ("10:00"t - ((timepart(end_dt) - "08:00"t)));&lt;/P&gt;&lt;P&gt;/*&amp;nbsp;&amp;nbsp;&amp;nbsp; output;*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else tot_time=tot_time+"10:00"t;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Mar 2015 15:59:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/time-difference-between-timestamps-during-business-hours/m-p/203362#M37883</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-03-17T15:59:01Z</dc:date>
    </item>
    <item>
      <title>Re: time difference between timestamps during business hours</title>
      <link>https://communities.sas.com/t5/SAS-Programming/time-difference-between-timestamps-during-business-hours/m-p/203363#M37884</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sounds like a "&lt;A href="http://support.sas.com/documentation/cdl/en/etsug/63939/HTML/default/viewer.htm#etsug_intervals_sect008.htm"&gt;Custom Time Interval&lt;/A&gt;" is what you need, perhaps you can use the &lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p12v9lpx7rlthin1cnpd320l3mj3.htm"&gt;"Holiday"&lt;/A&gt; function to help you determine other days to exclude.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Mar 2015 16:25:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/time-difference-between-timestamps-during-business-hours/m-p/203363#M37884</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2015-03-17T16:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: time difference between timestamps during business hours</title>
      <link>https://communities.sas.com/t5/SAS-Programming/time-difference-between-timestamps-during-business-hours/m-p/203364#M37885</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;
data holidays;
input date : date9.;
format date date9.;
cards;
01Jan2015
;
run;
data _null_;
if _n_ eq 1 then do;
 declare hash h(dataset:'holidays');
 h.definekey('date');
 h.definedone();
end;
time=-1;
 do i='30DEC2014:15:30:00'dt to '05JAN2015:09:52:00'dt ;
&amp;nbsp; date=datepart(i);
&amp;nbsp; if h.check() ne 0 and weekday(date) not in (1 7) then do;
&amp;nbsp;&amp;nbsp; if 8 le hour(i) lt 18 then time+1;
&amp;nbsp; end;
 end;
 putlog time time.;
run;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Mar 2015 14:05:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/time-difference-between-timestamps-during-business-hours/m-p/203364#M37885</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-03-18T14:05:24Z</dc:date>
    </item>
  </channel>
</rss>

