BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JM05
Calcite | Level 5

Hi everyone,

 

I'm trying to calculate the delay between 2 timestamps with a custom interval that represent business hours. (Entreprise Sas guide 7.1)

 

My issue : 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.

 

Is there a way to have a custom interval, with intervalds, that work with variable starting or ending outside the interval?

 

Thank you for the support

 

 

For the custom interval :

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;

 

 

 

Example of code for testing :

 

 

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;

 

 

 

Result :

TIME_START       MAJTIMESTAMP0   DELAI_M   DELAI_H
1890491098.7      1890518340                 .                 .

 

 

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;

 

 

 

Result:

TIME_START      MAJTIMESTAMP0    DELAI_M   DELAI_H
1890491098.7     1890493140                35             0.58

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
JM05
Calcite | Level 5

I had to move forward with the request, so I made a work around : 

 

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) >= '00:00:00't and timepart(MAJTIMESTAMP0) < '08:30:00't
		then MAJTIMESTAMP0 = dhms(datepart(MAJTIMESTAMP0),8,30,00);
	if timepart(MAJTIMESTAMP0) >= '18:30:00't and timepart(MAJTIMESTAMP0) <= '24:00:00't
		then MAJTIMESTAMP0 = dhms(datepart(MAJTIMESTAMP0),18,30,00);

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. 

 

It's not the perfect solution I was wishing but it's working 🙂 

 

 

 

 

View solution in original post

1 REPLY 1
JM05
Calcite | Level 5

I had to move forward with the request, so I made a work around : 

 

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) >= '00:00:00't and timepart(MAJTIMESTAMP0) < '08:30:00't
		then MAJTIMESTAMP0 = dhms(datepart(MAJTIMESTAMP0),8,30,00);
	if timepart(MAJTIMESTAMP0) >= '18:30:00't and timepart(MAJTIMESTAMP0) <= '24:00:00't
		then MAJTIMESTAMP0 = dhms(datepart(MAJTIMESTAMP0),18,30,00);

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. 

 

It's not the perfect solution I was wishing but it's working 🙂 

 

 

 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 406 views
  • 0 likes
  • 1 in conversation