DATA Step, Macro, Functions and more

Holiday Function

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 115
Accepted Solution

Holiday Function

Is there a way to generate a list of holidays (dates) referenced by the sas Holiday function.

Are these dates stored in a sashelp view?


Accepted Solutions
Solution
‎07-21-2011 02:05 PM
PROC Star
Posts: 7,363

Holiday Function

Couldn't you just roll your own by copying that list, excluding the dates you don't want, and including the years you want?  E.g.,

data holidays;

  informat holiday $20.;

  infile cards truncover;

  input holiday;

  cards;

BOXING           Boxing Day           December 26

CANADA           Canadian Independence Day           July 1

CANADAOBSERVED           Canadian Independence Day observed           July 1, or July 2 if July 1 is a Sunday

CHRISTMAS           Christmas           December 25

COLUMBUS           Columbus Day           2nd Monday in October

EASTER           Easter Sunday           date varies

FATHERS           Father's Day           3rd Sunday in June

HALLOWEEN           Halloween           October 31

LABOR           Labor Day           1st Monday in September

MLK           Martin Luther King, Jr. 's birthday           3rd Monday in January beginning in 1986

MEMORIAL           Memorial Day           last Monday in May (since 1971)

MOTHERS           Mother's Day           2nd Sunday in May

NEWYEAR           New Year's Day           January 1

THANKSGIVING           U.S. Thanksgiving Day           4th Thursday in November

THANKSGIVINGCANADA           Canadian Thanksgiving Day           2nd Monday in October

USINDEPENDENCE           U.S. Independence Day           July 4

USPRESIDENTS           Abraham Lincoln's and George Washington's birthdays observed           3rd Monday in February (since 1971)

VALENTINES           Valentine's Day           February 14

VETERANS           Veterans Day           November 11

VETERANSUSG           Veterans Day - U.S. government-observed           U.S. government-observed date for Monday-Friday schedule

VETERANSUSPS           Veterans Day - U.S. post office observed           U.S. government-observed date for Monday-Saturday schedule (U.S. Post Office)

VICTORIA           Victoria Day           Monday on or preceding May 24

;

data want;

  set holidays;

  do year=2005 to 2011;

    holiday_date=holiday(holiday,year);

    output;

  end;

run;

View solution in original post


All Replies
PROC Star
Posts: 7,363

Holiday Function

Frequent Contributor
Posts: 115

Holiday Function

Let me be a bit more specific about what I need.

I have a set of dates going back 6 years. I need to corss-reference my set of dates with the SAS holiday database so I can exclude past holidays from my dataset.

Solution
‎07-21-2011 02:05 PM
PROC Star
Posts: 7,363

Holiday Function

Couldn't you just roll your own by copying that list, excluding the dates you don't want, and including the years you want?  E.g.,

data holidays;

  informat holiday $20.;

  infile cards truncover;

  input holiday;

  cards;

BOXING           Boxing Day           December 26

CANADA           Canadian Independence Day           July 1

CANADAOBSERVED           Canadian Independence Day observed           July 1, or July 2 if July 1 is a Sunday

CHRISTMAS           Christmas           December 25

COLUMBUS           Columbus Day           2nd Monday in October

EASTER           Easter Sunday           date varies

FATHERS           Father's Day           3rd Sunday in June

HALLOWEEN           Halloween           October 31

LABOR           Labor Day           1st Monday in September

MLK           Martin Luther King, Jr. 's birthday           3rd Monday in January beginning in 1986

MEMORIAL           Memorial Day           last Monday in May (since 1971)

MOTHERS           Mother's Day           2nd Sunday in May

NEWYEAR           New Year's Day           January 1

THANKSGIVING           U.S. Thanksgiving Day           4th Thursday in November

THANKSGIVINGCANADA           Canadian Thanksgiving Day           2nd Monday in October

USINDEPENDENCE           U.S. Independence Day           July 4

USPRESIDENTS           Abraham Lincoln's and George Washington's birthdays observed           3rd Monday in February (since 1971)

VALENTINES           Valentine's Day           February 14

VETERANS           Veterans Day           November 11

VETERANSUSG           Veterans Day - U.S. government-observed           U.S. government-observed date for Monday-Friday schedule

VETERANSUSPS           Veterans Day - U.S. post office observed           U.S. government-observed date for Monday-Saturday schedule (U.S. Post Office)

VICTORIA           Victoria Day           Monday on or preceding May 24

;

data want;

  set holidays;

  do year=2005 to 2011;

    holiday_date=holiday(holiday,year);

    output;

  end;

run;

Frequent Contributor
Posts: 115

Holiday Function

That's a good idea.

I guess I just assumed there was some view or table that had these.

PROC Star
Posts: 7,363

Holiday Function

There might be but, since (according to the documentation) one can't add holidays to it, I've never looked for one.  On the other hand, at least this way you can exclude any days that you don't want considered.

Regular Contributor
Posts: 184

Holiday Function

It's somewhat unlikely that the holiday set which SAS uses will conform to the holiday set appropriate to your business. For techniques to generate custom holiday lists, see

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

Unfortunately these cannot be utilized with the HOLIDAY function.

Jaime wrote:

Let me be a bit more specific about what I need.

I have a set of dates going back 6 years. I need to corss-reference my set of dates with the SAS holiday database so I can exclude past holidays from my dataset.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 2254 views
  • 0 likes
  • 3 in conversation