SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
EarlyCode
Fluorite | Level 6

So I was browsing the SAS for Dummies blog and came across this post.

 

http://blogs.sas.com/content/sasdummy/2011/05/09/calculating-the-number-of-working-days-between-two-...

 

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?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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)

View solution in original post

1 REPLY 1
ballardw
Super User

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)

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1396 views
  • 0 likes
  • 2 in conversation