Tuesday, January 3, 2017

Hack 4.6 Determining The Dates of Major Holidays with the HOLIDAY Function


SAS Programming Professionals,

Did you know that the HOLIDAY function allows you to determine the date of major US and Canadian holidays? 

You simply supply the HOLIDAY function with the holiday keyword and the year, and it will return the SAS date value.  The syntax looks like this:

               HOLIDAY('holiday',year)

Here is an example that computes three holidays for the next ten years:

data future_holidays;

label year = "Year"
      mothersday= "Mothers Day"
      presidentsday = "Presidents Day"
      victoriaday = "Victoria Day"
      ;
format mothersday presidentsday victoriaday worddate.;

do year = 2015 to 2025 by 1;

mothersday = holiday("MOTHERS",year);
presidentsday=holiday("USPRESIDENTS",year);
victoriaday=holiday("VICTORIA",year);
output;
end;

run;

proc print noobs label;
run;

There are currently twenty-two holiday keywords for the HOLIDAY function.  You can read more about the HOLIDAY function, including all of the available holiday keywords, in the SAS online documentation on the support.sas.com web site.
Best of luck in all your SAS endeavors!

---MMMMIIIIKKKKEEEE
(aka Michael A. Raithel)
Author of the new cult classic for computer programmers:  It Only Hurts When I Hit <ENTER>
Print edition:  http://tinyurl.com/z8bzx2e 
Kindle edition: http://tinyurl.com/zypgqa7 

The hack above is an excerpt from the book:  Did You Know That?  Essential Hacks for Clever SAS Programmers

No comments:

Post a Comment