Yes, you can programmatically determine the date for
calendar events by using DATA step functions and
various date intervals. For more information about
the functions and intervals that are used in the
following example, see SAS 9.1 Language
Reference: Dictionary and SAS 9.1 Language
Reference: Concepts.
/* Verify YEAR value. */
%LET YEAR=2001;
/* Determine dates for various calendar events.*/
DATA _NULL_;
/* FDO-prefixed variables are First Day Of... For */
/* example, FDOY is First Day of Year. */
FDOY=MDY(1,1,&YEAR);
/* Martin Luther King Day. */
MLK_DAY=INTNX('WEEK.2',FDOY,(WEEKDAY(FDOY) NE 2)+2);
/* Presidents' Day. */
FDO_FEB=INTNX('MONTH',FDOY,1);
PRES_DAY=INTNX('WEEK.2',FDO_FEB,(WEEKDAY(FDO_FEB) NE 2)+2);
/* Daylight saving time begins. */
FDO_MAR=INTNX('MONTH',FDOY,2);
DST_BEG=INTNX('WEEK.1',FDO_mar,(WEEKDAY(FDO_MAR) NE 1)+1);
/* Memorial Day. */
FDO_MAY=INTNX('MONTH',FDOY,4);
MEM_DAY=INTNX('WEEK.2',FDO_MAY,(WEEKDAY(FDO_MAY) IN (1,7))+4);
/* Independence Day. */
IND_DAY=MDY(7,4,&YEAR);
/* Labor Day. */
FDO_SEP=INTNX('MONTH',FDOY,8);
LAB_DAY=INTNX('WEEK.2',FDO_SEP,(WEEKDAY(FDO_SEP) NE 2));
/* Columbus Day. */
FDO_OCT=INTNX('MONTH',FDOY,9);
COL_DAY=INTNX('WEEK.2',FDO_OCT,(WEEKDAY(FDO_OCT) NE 2)+1);
/* Daylight saving time ends. */
FDO_NOV=INTNX('MONTH',FDOY,10);
DST_END=INTNX('WEEK.1',FDO_NOV,(WEEKDAY(FDO_NOV) NE 1));
/* Election Day. */
FDO_NOV=INTNX('MONTH',FDOY,10);
ELEC_DAY=INTNX('WEEK.3',FDO_NOV,1);
/* Veterans Day. */
VET_DAY=MDY(11,11,&YEAR);
/*Thanksgiving Day */
THKS_DAY=INTNX('WEEK.5',FDO_NOV,(WEEKDAY(FDO_NOV) NE 5)+3);
/* Christmas Day. */
XMAS_DAY=MDY(12,25,&YEAR);
/* Write results to SAS Log. */
PUT MLK_DAY= WORDDATE. /
PRES_DAY= WORDDATE. /
DST_BEG= WORDDATE. /
MEM_DAY= WORDDATE. /
IND_DAY= WORDDATE. /
LAB_DAY= WORDDATE. /
COL_DAY= WORDDATE. /
DST_END= WORDDATE. /
ELEC_DAY= WORDDATE. /
VET_DAY= WORDDATE. /
THKS_DAY= WORDDATE. /
XMAS_DAY= WORDDATE. /
;
RUN;
Beginning in SAS 9.2 you can use the new HOLIDAY function to do what the code in this example does.
Click here to see information about the new HOLIDAY function
Operating System and Release Information
| SAS System | N/A | All | n/a | |
| SAS System | Base SAS | All | n/a | |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.