BookmarkSubscribeRSS Feed
sas1011
Calcite | Level 5

Hello,

I have been breaking my head trying to get this to work. 

 

I have a data set with two datetime columns and another dataset with list of holidays and weekends.

 

I need to calculate the total hours between the two datetimes - and if any holiday and/or weekend falls between these dates, that day(24hours) needs to be removed from the total. 

 

Please help me with the easiest way to do it. 

 

This is what I am working with in terms of logic:

 

data want;

set have;

var1=0;

array hol(*) hol1-hol141;

do i=1 to dim(hol);

if hol(i) ge datepart(datetime1) and hol(i) le datepart(datetime2) then

var1+24;

 

Net_hours=(intck('seconds', datetime1, datetime2)/(60*60)) - var1;

run;

2 REPLIES 2
mkeintz
PROC Star

Do any of your datetime values occur within a holiday or weekend?  And if so, do you then need to subtract only a corresponding fraction of the 24 hours?

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Reeza
Super User

Although you're doing hours, this is probably the same question:

https://communities.sas.com/t5/SAS-Programming/Finding-the-next-working-day-with-a-custom-calendar/t...

 

You really do want to create a custom calendar though, it'll save you a lot of time and headache once you get it working. It's tedious but not complicated.

 

This is perhaps the better reference:

https://communities.sas.com/t5/SAS-Communities-Library/SAS-Tip-Generating-Holiday-Lists/ta-p/557799?...

 


@sas1011 wrote:

Hello,

I have been breaking my head trying to get this to work. 

 

I have a data set with two datetime columns and another dataset with list of holidays and weekends.

 

I need to calculate the total hours between the two datetimes - and if any holiday and/or weekend falls between these dates, that day(24hours) needs to be removed from the total. 

 

Please help me with the easiest way to do it. 

 

This is what I am working with in terms of logic:

 

data want;

set have;

var1=0;

array hol(*) hol1-hol141;

do i=1 to dim(hol);

if hol(i) ge datepart(datetime1) and hol(i) le datepart(datetime2) then

var1+24;

 

Net_hours=(intck('seconds', datetime1, datetime2)/(60*60)) - var1;

run;