<?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: Get differences between 2 datetimes in hours WITHOUT Sundays or holidays in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Get-differences-between-2-datetimes-in-hours-WITHOUT-Sundays-or/m-p/925009#M41510</link>
    <description>&lt;P&gt;This works perfectly. However, for a big data set, it is impossibly slow. Is there are way for the do loop to ititerate through minutes or hours rather than seconds?&lt;/P&gt;</description>
    <pubDate>Fri, 19 Apr 2024 15:24:56 GMT</pubDate>
    <dc:creator>kz_</dc:creator>
    <dc:date>2024-04-19T15:24:56Z</dc:date>
    <item>
      <title>Get differences between 2 datetimes in hours WITHOUT Sundays or holidays</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Get-differences-between-2-datetimes-in-hours-WITHOUT-Sundays-or/m-p/924034#M41446</link>
      <description>&lt;P&gt;I need to calculate the difference between two datetimes in hours, but I need to exclude Sundays and the following holidays:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. New Year's Day&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Memorial Day&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. July 4&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4. Labor Day&amp;nbsp;&lt;/P&gt;
&lt;P&gt;5. Thanksgiving&amp;nbsp;&lt;/P&gt;
&lt;P&gt;6. Christmas&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, using INTCK, I get column 3. I want column 4. I know there is a weekday function, but I don't know how to use it and include Saturdays.&lt;/P&gt;
&lt;P&gt;Thanks in advance.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1" width="99.97324772605671%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="24.986623863028356%" height="30px" class="dgrid-cell dgrid-cell-padding dgrid-column-2 field-col2 dgrid-focus"&gt;second_time&lt;/TD&gt;
&lt;TD width="24.986623863028356%" height="30px" class="dgrid-cell dgrid-cell-padding dgrid-column-3 field-col3"&gt;first_time&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;intck('dthour', first_time, second_time)&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;WANT&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;Why?&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="24.986623863028356%" height="30px" class="dgrid-cell dgrid-cell-padding dgrid-column-2 field-col2"&gt;04MAR24:12:26:00&lt;/TD&gt;
&lt;TD width="24.986623863028356%" height="30px" class="dgrid-cell dgrid-cell-padding dgrid-column-3 field-col3 dgrid-focus"&gt;01MAR24:11:30:00&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;73&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;49&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;Exclude March 3 (Sunday)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="24.986623863028356%" height="30px" class="dgrid-cell dgrid-cell-padding dgrid-column-2 field-col2 dgrid-focus"&gt;28MAY24:10:54:00&lt;/TD&gt;
&lt;TD width="24.986623863028356%" height="30px" class="dgrid-cell dgrid-cell-padding dgrid-column-3 field-col3"&gt;21MAY24:21:15:00&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;157&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;109&lt;/TD&gt;
&lt;TD width="12.5%" height="30px"&gt;Exclude May 26 (Sunday) and May 27 (Memorial Day)&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="24.986623863028356%" height="57px" class="dgrid-cell dgrid-cell-padding dgrid-column-2 field-col2 dgrid-focus"&gt;01MAR24:09:53:00&lt;/TD&gt;
&lt;TD width="24.986623863028356%" height="57px" class="dgrid-cell dgrid-cell-padding dgrid-column-3 field-col3"&gt;01MAR24:09:15:00&lt;/TD&gt;
&lt;TD width="25%" height="57px"&gt;0&lt;/TD&gt;
&lt;TD width="12.5%" height="57px"&gt;0 or 1&amp;nbsp;&lt;/TD&gt;
&lt;TD width="12.5%" height="57px"&gt;SAS is rounding down, but up is ok too&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Thu, 11 Apr 2024 21:26:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Get-differences-between-2-datetimes-in-hours-WITHOUT-Sundays-or/m-p/924034#M41446</guid>
      <dc:creator>kz_</dc:creator>
      <dc:date>2024-04-11T21:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: Get differences between 2 datetimes in hours WITHOUT Sundays or holidays</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Get-differences-between-2-datetimes-in-hours-WITHOUT-Sundays-or/m-p/924037#M41447</link>
      <description>&lt;P&gt;You have to create a custom interval.&lt;/P&gt;
&lt;P&gt;There is sample code in the docu that's already close to what you need:&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/etsug/etsug_intervals_sect008.htm" target="_self"&gt;example uses custom intervals in the time function INTCK to omit holidays when counting business days&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Apr 2024 00:45:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Get-differences-between-2-datetimes-in-hours-WITHOUT-Sundays-or/m-p/924037#M41447</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-04-12T00:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: Get differences between 2 datetimes in hours WITHOUT Sundays or holidays</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Get-differences-between-2-datetimes-in-hours-WITHOUT-Sundays-or/m-p/924047#M41448</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
You need the help of function WEEKDAY() and HOLIDAY().
*/
data have;
infile cards expandtabs truncover;
input (second_time	first_time) (: datetime32.);
format second_time	first_time datetime.;
seconds=0;
do temp=first_time to second_time;
 if weekday(datepart(temp)) ne 1 and
    datepart(temp) ne holiday('NEWYEAR',year(datepart(temp))) and
	datepart(temp) ne holiday('MEMORIAL',year(datepart(temp))) and
    datepart(temp) ne holiday('USINDEPENDENCE',year(datepart(temp))) and
	datepart(temp) ne holiday('LABOR',year(datepart(temp))) and
	datepart(temp) ne holiday('THANKSGIVING',year(datepart(temp))) and
	datepart(temp) ne holiday('CHRISTMAS',year(datepart(temp))) then seconds+1;
end;
want=seconds/'01:00:00't;
drop temp seconds;
cards;
04MAR24:12:26:00	01MAR24:11:30:00	
28MAY24:10:54:00	21MAY24:21:15:00
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Apr 2024 02:58:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Get-differences-between-2-datetimes-in-hours-WITHOUT-Sundays-or/m-p/924047#M41448</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-04-12T02:58:19Z</dc:date>
    </item>
    <item>
      <title>Re: Get differences between 2 datetimes in hours WITHOUT Sundays or holidays</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Get-differences-between-2-datetimes-in-hours-WITHOUT-Sundays-or/m-p/925009#M41510</link>
      <description>&lt;P&gt;This works perfectly. However, for a big data set, it is impossibly slow. Is there are way for the do loop to ititerate through minutes or hours rather than seconds?&lt;/P&gt;</description>
      <pubDate>Fri, 19 Apr 2024 15:24:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Get-differences-between-2-datetimes-in-hours-WITHOUT-Sundays-or/m-p/925009#M41510</guid>
      <dc:creator>kz_</dc:creator>
      <dc:date>2024-04-19T15:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: Get differences between 2 datetimes in hours WITHOUT Sundays or holidays</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Get-differences-between-2-datetimes-in-hours-WITHOUT-Sundays-or/m-p/925057#M41519</link>
      <description>&lt;P&gt;Since datetimes are numbers of seconds change any increment to a multiple you like:&lt;/P&gt;
&lt;PRE&gt;do temp=first_time to second_time&lt;STRONG&gt; by 60&lt;/STRONG&gt;;
 if weekday(datepart(temp)) ne 1 and
    datepart(temp) ne holiday('NEWYEAR',year(datepart(temp))) and
	datepart(temp) ne holiday('MEMORIAL',year(datepart(temp))) and
    datepart(temp) ne holiday('USINDEPENDENCE',year(datepart(temp))) and
	datepart(temp) ne holiday('LABOR',year(datepart(temp))) and
	datepart(temp) ne holiday('THANKSGIVING',year(datepart(temp))) and
	datepart(temp) ne holiday('CHRISTMAS',year(datepart(temp))) then seconds&lt;STRONG&gt;+60;&lt;/STRONG&gt;
end;&lt;/PRE&gt;
&lt;P&gt;increments by 60 seconds or one minute&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;do temp=first_time to second_time&lt;STRONG&gt; by 3600&lt;/STRONG&gt;;
 if weekday(datepart(temp)) ne 1 and
    datepart(temp) ne holiday('NEWYEAR',year(datepart(temp))) and
	datepart(temp) ne holiday('MEMORIAL',year(datepart(temp))) and
    datepart(temp) ne holiday('USINDEPENDENCE',year(datepart(temp))) and
	datepart(temp) ne holiday('LABOR',year(datepart(temp))) and
	datepart(temp) ne holiday('THANKSGIVING',year(datepart(temp))) and
	datepart(temp) ne holiday('CHRISTMAS',year(datepart(temp))) then seconds&lt;STRONG&gt;+3600&lt;/STRONG&gt;;
end;&lt;/PRE&gt;
&lt;P&gt;increment by 3600 seconds or 1 hour.&lt;/P&gt;
&lt;P&gt;24*3600= 24 hours (1 day).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Apr 2024 18:53:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Get-differences-between-2-datetimes-in-hours-WITHOUT-Sundays-or/m-p/925057#M41519</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-04-19T18:53:18Z</dc:date>
    </item>
  </channel>
</rss>

