<?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 intervalds and INTCK not counting when starting out of bound in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/intervalds-and-INTCK-not-counting-when-starting-out-of-bound/m-p/608126#M177185</link>
    <description>&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif" size="3"&gt;Hi everyone,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif" size="3"&gt;I'm trying to calculate the delay between 2 timestamps with a custom interval that represent business hours.&amp;nbsp;(Entreprise Sas guide 7.1)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif" size="3"&gt;My issue&amp;nbsp;: if the starting or the ending timestamps is out of the business hours (not included in my custom interval), it doesn't calculate the delay for the time included in the custom interval and return a null value.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif" size="3"&gt;Is there a way to have a custom interval, with intervalds, that work with variable starting or ending outside the interval?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif" size="3"&gt;Thank you for the support&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif" size="3"&gt;For the custom interval :&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data StoreHour(keep=BEGIN END);
    start = '01JAN2019'D;
    stop = '31DEC2021'D;
     do date = start to stop;
         dow = WEEKDAY(date);
         datetime=dhms(date,0,0,0);
          if dow not in (1,7) then
             do minute = 510 to 1110;   /*8:30 to 18:30 */
                    begin=intnx('minute',datetime,minute,'b');
                    end=intnx('minute',datetime,minute,'e');
  output;
  end;
end;
format BEGIN END DATETIME.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif" size="3"&gt;Example of code for testing :&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options intervalds=(StoreHours=StoreHour); 

data step1;
    TIME_START = '27NOV2019:16:24:58.732616'dt;
    MAJTIMESTAMP0 = '27NOV2019:23:59:00.000000'dt;
    DELAI_M = INTCK('StoreHours',TIME_START,MAJTIMESTAMP0); 
    DELAI_H = round(DELAI_M/60,.01);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif" size="3"&gt;Result : &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif" size="3"&gt;TIME_START&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MAJTIMESTAMP0&amp;nbsp;&amp;nbsp; DELAI_M&amp;nbsp;&amp;nbsp; DELAI_H&lt;BR /&gt;1890491098.7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1890518340&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;&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;.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data step2;
    TIME_START = '27NOV2019:16:24:58.732616'dt;
    MAJTIMESTAMP0 = '27NOV2019:16:59:00.000000'dt;
    DELAI_M = INTCK('StoreHours',TIME_START,MAJTIMESTAMP0); 
    DELAI_H = round(DELAI_M/60,.01);
run;

 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif" size="3"&gt;Result: &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif" size="3"&gt;TIME_START&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MAJTIMESTAMP0&amp;nbsp;&amp;nbsp;&amp;nbsp; DELAI_M&amp;nbsp;&amp;nbsp; DELAI_H&lt;BR /&gt;1890491098.7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1890493140&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; 35&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;0.58&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Nov 2019 20:46:03 GMT</pubDate>
    <dc:creator>JM05</dc:creator>
    <dc:date>2019-11-28T20:46:03Z</dc:date>
    <item>
      <title>intervalds and INTCK not counting when starting out of bound</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intervalds-and-INTCK-not-counting-when-starting-out-of-bound/m-p/608126#M177185</link>
      <description>&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif" size="3"&gt;Hi everyone,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif" size="3"&gt;I'm trying to calculate the delay between 2 timestamps with a custom interval that represent business hours.&amp;nbsp;(Entreprise Sas guide 7.1)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif" size="3"&gt;My issue&amp;nbsp;: if the starting or the ending timestamps is out of the business hours (not included in my custom interval), it doesn't calculate the delay for the time included in the custom interval and return a null value.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif" size="3"&gt;Is there a way to have a custom interval, with intervalds, that work with variable starting or ending outside the interval?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif" size="3"&gt;Thank you for the support&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif" size="3"&gt;For the custom interval :&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data StoreHour(keep=BEGIN END);
    start = '01JAN2019'D;
    stop = '31DEC2021'D;
     do date = start to stop;
         dow = WEEKDAY(date);
         datetime=dhms(date,0,0,0);
          if dow not in (1,7) then
             do minute = 510 to 1110;   /*8:30 to 18:30 */
                    begin=intnx('minute',datetime,minute,'b');
                    end=intnx('minute',datetime,minute,'e');
  output;
  end;
end;
format BEGIN END DATETIME.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif" size="3"&gt;Example of code for testing :&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options intervalds=(StoreHours=StoreHour); 

data step1;
    TIME_START = '27NOV2019:16:24:58.732616'dt;
    MAJTIMESTAMP0 = '27NOV2019:23:59:00.000000'dt;
    DELAI_M = INTCK('StoreHours',TIME_START,MAJTIMESTAMP0); 
    DELAI_H = round(DELAI_M/60,.01);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif" size="3"&gt;Result : &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif" size="3"&gt;TIME_START&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MAJTIMESTAMP0&amp;nbsp;&amp;nbsp; DELAI_M&amp;nbsp;&amp;nbsp; DELAI_H&lt;BR /&gt;1890491098.7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1890518340&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;&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;.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data step2;
    TIME_START = '27NOV2019:16:24:58.732616'dt;
    MAJTIMESTAMP0 = '27NOV2019:16:59:00.000000'dt;
    DELAI_M = INTCK('StoreHours',TIME_START,MAJTIMESTAMP0); 
    DELAI_H = round(DELAI_M/60,.01);
run;

 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif" size="3"&gt;Result: &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif" size="3"&gt;TIME_START&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MAJTIMESTAMP0&amp;nbsp;&amp;nbsp;&amp;nbsp; DELAI_M&amp;nbsp;&amp;nbsp; DELAI_H&lt;BR /&gt;1890491098.7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1890493140&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; 35&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;0.58&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Nov 2019 20:46:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intervalds-and-INTCK-not-counting-when-starting-out-of-bound/m-p/608126#M177185</guid>
      <dc:creator>JM05</dc:creator>
      <dc:date>2019-11-28T20:46:03Z</dc:date>
    </item>
    <item>
      <title>Re: intervalds and INTCK not counting when starting out of bound</title>
      <link>https://communities.sas.com/t5/SAS-Programming/intervalds-and-INTCK-not-counting-when-starting-out-of-bound/m-p/608860#M177240</link>
      <description>&lt;P&gt;I had to move forward with the request, so I made a work around :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;if weekday(datepart(MAJTIMESTAMP0)) = 7 
		then MAJTIMESTAMP0 = dhms(datepart(MAJTIMESTAMP0)-1,18,30,00);
	if weekday(datepart(MAJTIMESTAMP0)) = 1 
		then MAJTIMESTAMP0 = dhms(datepart(MAJTIMESTAMP0)-2,18,30,00);
	if timepart(MAJTIMESTAMP0) &amp;gt;= '00:00:00't and timepart(MAJTIMESTAMP0) &amp;lt; '08:30:00't
		then MAJTIMESTAMP0 = dhms(datepart(MAJTIMESTAMP0),8,30,00);
	if timepart(MAJTIMESTAMP0) &amp;gt;= '18:30:00't and timepart(MAJTIMESTAMP0) &amp;lt;= '24:00:00't
		then MAJTIMESTAMP0 = dhms(datepart(MAJTIMESTAMP0),18,30,00);&lt;/PRE&gt;&lt;P&gt;I change the saturday and sunday to the previous friday and I change the timestamp to be at the begenning or the ending of the custom interval.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's not the perfect solution I was wishing but it's working &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2019 21:17:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/intervalds-and-INTCK-not-counting-when-starting-out-of-bound/m-p/608860#M177240</guid>
      <dc:creator>JM05</dc:creator>
      <dc:date>2019-12-02T21:17:59Z</dc:date>
    </item>
  </channel>
</rss>

