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

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
Reeza
Super User

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 😉

View solution in original post

3 REPLIES 3
ballardw
Super User

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.

 

mmyrto
Quartz | Level 8

New Year's Day 

Martin Luther King Day

 

Memorial Day

 

Independence Day

 

Labor Day

 

 

Christmas Day Observance

Reeza
Super User

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 😉

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

Multiple Linear Regression in SAS

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.

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