So I was browsing the SAS for Dummies blog and came across this post.
Which I thought was interesting, but I was wondering if it could be improved.
Some holidays are set, like January 1st, fourth of July, veteran's day, and always occur on the same day each year. But others are determined by weekday of the month rather than date.
My office has a set list of holidays which comes down to,
Jan 1st,
Third Monday of January
Last Monday of May (could be the fourth or fifth monday depending on year)
July 4th
First Monday of Sept
November 11th
4th Thursday of November
December 25th.
(And if 01/01, 07/04, 11/11, or 12/25 is ever on a Sunday, then the holiday is observed on the following Monday.)
The custom function in the blog post would require someone to update the table with the holiday dates for all these variable holidays every year. Is there a way to have a program automatically create a volatile table to calculate for these dates that would then be used in the custom function?
For typical US and Canadaian holidays at least, which you list looks like you may want to investigate the Holiday function.
You give the function the name of the holiday and the year and function returns a SAS date value for the given holiday:
data _Null_;
LaborDay = Holiday('Labor',2016);
put LaborDay mmddyy10.;
run;
For example.
For those that may be observed on different days other than those that the function has designed it isn't too dificult to adjust using the
WEEKDAY function
If weekday(holiday('christmas',2016))=1 then ChristmasObserved= holiday('christmas',2016) +1;
(sunday is weekday 1, saturday weekday 7)
For typical US and Canadaian holidays at least, which you list looks like you may want to investigate the Holiday function.
You give the function the name of the holiday and the year and function returns a SAS date value for the given holiday:
data _Null_;
LaborDay = Holiday('Labor',2016);
put LaborDay mmddyy10.;
run;
For example.
For those that may be observed on different days other than those that the function has designed it isn't too dificult to adjust using the
WEEKDAY function
If weekday(holiday('christmas',2016))=1 then ChristmasObserved= holiday('christmas',2016) +1;
(sunday is weekday 1, saturday weekday 7)
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.