LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (June 2007, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 27 Jun 2007 21:52:19 -0400
Reply-To:     "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Howard Schreier <hs AT dc-sug DOT org>" <nospam@HOWLES.COM>
Subject:      Re: Xmas and Labor Day

On Tue, 26 Jun 2007 23:24:29 -0400, Thien Thai <coithienthai2002@YAHOO.COM.AU> wrote:

>Hello SAS experts > >I have a task which requires generating Xmas & Labor Day dates which >follows this logic for the period 1970-2007 > >i) the 1st Monday in October (Labor Day); >ii) Xmas Day, or, if that day falls on a Saturday or Sunday, the following >Monday; >iii) 26 December (Boxing Day), or- >(A) if that day falls on a Saturday-the following Monday; or >(B) if that day falls on a Sunday or Monday-the following Tuesday; > >Much apreciated if anyone can show me an algorithm that help me to do this.

Try this:

data holidays; do year = 1970 to 2007; LaborDay = intnx('week.2', mdy(9,30,year), 1); Christmas = mdy(12,25,year) + max(0,-mod(weekday(mdy(12,25,year)),7)+2); BoxingDay = Christmas + 1 + 2 * (weekday(Christmas)=6); output; end; format LaborDay Christmas BoxingDay weekdate17.; run;

The logic for Labor Day is to take the last day in the previous month, then advance to the start of the next Monday-to-Sunday week.

The logic for Christmas is to start with December 25, then add an adjustment term which evaluates to 2 for Saturday, 1 for Sunday, and 0 for any other day.

The logic for Boxing Day is to take the day after Christmas, unless Christmas is observed on Friday (in which case Boxing Day is advanced by 2 days).

Results below.

I also want to suggest a different approach to this type of problem. Consider that there are only 14 possible distinct years under the Gregorian calendar; 7 possible starting days x 2 possible leap-year states.

One could manually or semi-manually build a table designating the holidays of interest over those 14 "master" years. The columns would be StartingDay, LeapYear, Holiday, Month, Day.

Then, to generate the holiday schedule for specific years, one would only have to classify those years in terms of starting day and leap-year state, then join the year list to the master.

Results from code shown above:

year LaborDay Christmas BoxingDay

1970 Mon, Oct 5, 1970 Fri, Dec 25, 1970 Mon, Dec 28, 1970 1971 Mon, Oct 4, 1971 Mon, Dec 27, 1971 Tue, Dec 28, 1971 1972 Mon, Oct 2, 1972 Mon, Dec 25, 1972 Tue, Dec 26, 1972 1973 Mon, Oct 1, 1973 Tue, Dec 25, 1973 Wed, Dec 26, 1973 1974 Mon, Oct 7, 1974 Wed, Dec 25, 1974 Thu, Dec 26, 1974 1975 Mon, Oct 6, 1975 Thu, Dec 25, 1975 Fri, Dec 26, 1975 1976 Mon, Oct 4, 1976 Mon, Dec 27, 1976 Tue, Dec 28, 1976 1977 Mon, Oct 3, 1977 Mon, Dec 26, 1977 Tue, Dec 27, 1977 1978 Mon, Oct 2, 1978 Mon, Dec 25, 1978 Tue, Dec 26, 1978 1979 Mon, Oct 1, 1979 Tue, Dec 25, 1979 Wed, Dec 26, 1979 1980 Mon, Oct 6, 1980 Thu, Dec 25, 1980 Fri, Dec 26, 1980 1981 Mon, Oct 5, 1981 Fri, Dec 25, 1981 Mon, Dec 28, 1981 1982 Mon, Oct 4, 1982 Mon, Dec 27, 1982 Tue, Dec 28, 1982 1983 Mon, Oct 3, 1983 Mon, Dec 26, 1983 Tue, Dec 27, 1983 1984 Mon, Oct 1, 1984 Tue, Dec 25, 1984 Wed, Dec 26, 1984 1985 Mon, Oct 7, 1985 Wed, Dec 25, 1985 Thu, Dec 26, 1985 1986 Mon, Oct 6, 1986 Thu, Dec 25, 1986 Fri, Dec 26, 1986 1987 Mon, Oct 5, 1987 Fri, Dec 25, 1987 Mon, Dec 28, 1987 1988 Mon, Oct 3, 1988 Mon, Dec 26, 1988 Tue, Dec 27, 1988 1989 Mon, Oct 2, 1989 Mon, Dec 25, 1989 Tue, Dec 26, 1989 1990 Mon, Oct 1, 1990 Tue, Dec 25, 1990 Wed, Dec 26, 1990 1991 Mon, Oct 7, 1991 Wed, Dec 25, 1991 Thu, Dec 26, 1991 1992 Mon, Oct 5, 1992 Fri, Dec 25, 1992 Mon, Dec 28, 1992 1993 Mon, Oct 4, 1993 Mon, Dec 27, 1993 Tue, Dec 28, 1993 1994 Mon, Oct 3, 1994 Mon, Dec 26, 1994 Tue, Dec 27, 1994 1995 Mon, Oct 2, 1995 Mon, Dec 25, 1995 Tue, Dec 26, 1995 1996 Mon, Oct 7, 1996 Wed, Dec 25, 1996 Thu, Dec 26, 1996 1997 Mon, Oct 6, 1997 Thu, Dec 25, 1997 Fri, Dec 26, 1997 1998 Mon, Oct 5, 1998 Fri, Dec 25, 1998 Mon, Dec 28, 1998 1999 Mon, Oct 4, 1999 Mon, Dec 27, 1999 Tue, Dec 28, 1999 2000 Mon, Oct 2, 2000 Mon, Dec 25, 2000 Tue, Dec 26, 2000 2001 Mon, Oct 1, 2001 Tue, Dec 25, 2001 Wed, Dec 26, 2001 2002 Mon, Oct 7, 2002 Wed, Dec 25, 2002 Thu, Dec 26, 2002 2003 Mon, Oct 6, 2003 Thu, Dec 25, 2003 Fri, Dec 26, 2003 2004 Mon, Oct 4, 2004 Mon, Dec 27, 2004 Tue, Dec 28, 2004 2005 Mon, Oct 3, 2005 Mon, Dec 26, 2005 Tue, Dec 27, 2005 2006 Mon, Oct 2, 2006 Mon, Dec 25, 2006 Tue, Dec 26, 2006 2007 Mon, Oct 1, 2007 Tue, Dec 25, 2007 Wed, Dec 26, 2007


Back to: Top of message | Previous page | Main SAS-L page