Quartz | Level 8

## Excluding holidays and weekends from monthly time series data

I have monthly time series data that i want to adjust based on number of working days in the month. i figured how to exclude the weekends using the following macro:

data Regions2;
set Regions;
format Date last_day mmddyy10.;
do year = 2013 to 2016;
do month = 1 to 12;
Date = mdy(month, 1, year);
last_day = intnx('month', Date, 0, 'e');
days = intck('day', Date, last_day) + 1;
weekdays = intck('weekday', Date, last_day) + 1;
weeks = intck('week', Date, last_day);
hours = intck('dthour', dhms(Date, 0, 0,0), dhms(last_day, 23, 59, 59)) + 1;
work_hours = weekdays * 8;
by region;
output;
end; /* end month */
end; /* end year */
label
Date = 'First day'
last_day = 'Last day'
days = 'Days'
weekdays = 'Week days'
weeks = 'Weeks'
hours = 'Hours'
work_hours = 'Work hours'
;
drop month year;
run;

but how do i also take into account the holidays in the calculations above?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: Excluding holidays and weekends from monthly time series data

Since those dates aren't in the calendar you have to make your own calendar and then you can use that custom interval instead of the weekday interval in the intnx and intck functions.

There's a bit of a write up on it here:

http://www.sascommunity.org/wiki/Generating_Holiday_Lists

Keep in mind that Christmas observance can be very company specific, for example, Christmas Eve is included in my companies benefits.

BTW - none of this is macro logic 😉

3 REPLIES 3
Super User

## Re: Excluding holidays and weekends from monthly time series data

Which holidays?

SAS has a function HOLIDAY that returns the date of a specified holiday for a given year.

``````data _null_;
x=holiday('easter',2016);
put 'Easter is ' x mmddyy10.;
run;``````

So for US and Canada at least you can get dates of specific holidays.

Quartz | Level 8

## Re: Excluding holidays and weekends from monthly time series data

New Year's Day

Martin Luther King Day

Memorial Day

Independence Day

Labor Day

Christmas Day Observance

Super User

## Re: Excluding holidays and weekends from monthly time series data

Since those dates aren't in the calendar you have to make your own calendar and then you can use that custom interval instead of the weekday interval in the intnx and intck functions.

There's a bit of a write up on it here:

http://www.sascommunity.org/wiki/Generating_Holiday_Lists

Keep in mind that Christmas observance can be very company specific, for example, Christmas Eve is included in my companies benefits.

BTW - none of this is macro logic 😉

Discussion stats
• 3 replies
• 3071 views
• 0 likes
• 3 in conversation