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
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 😉
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.
New Year's Day
Martin Luther King Day
Memorial Day
Independence Day
Labor Day
Christmas Day Observance
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 😉
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.