Sample 24735: Compute daylight saving time
Determine the start and end dates for daylight saving time for given years.
/*********************************************************************/
/* The following code calculates the start and end dates for */
/* daylight saving time for the years 2006 through 2009. */
/* */
/* FDOY represents the first day of the year */
/* FDO_APR represents the first day of April */
/* DST_BEG represents the first day of daylight saving time */
/* */
/* It is calculated using this syntax: */
/* intnx('week.1',fdo_apr,(weekday(fdo_apr) ne 1)) */
/* */
/* Explanation of the above syntax: */
/* - weekday(fdo_apr) returns a number between 1 and 7, */
/* which represents the day of the week, 1=Sunday and 7=Saturday */
/* */
/* - weekday(fdo_apr) ne 1) returns a 0 if the first day */
/* of April is a Sunday and 1 otherwise. */
/* */
/* - intnx('week.1',fdo_apr,(weekday(fdo_apr) ne 1)) returns a */
/* SAS date which is 0 WEEK intervals from the FDO_APR, if the */
/* first day of April is a Sunday. The WEEK.1 interval specifies */
/* Sunday as the first day of the week. */
/* */
/* OR */
/* */
/* returns a SAS date which is 1 WEEK interval from the FDO_APR, */
/* if the first day of April is not a Sunday, (using Sunday as */
/* the first day of the week). */
/* */
/* */
/* DST_END represents the end of daylight saving time and is */
/* calculated similarly to DST_BEG. */
/*********************************************************************/
data _null_;
do year=2006 to 2009;
fdoy=mdy(1,1,year);
/* For years prior to 2007, daylight time begins in the United States on */
/* the first Sunday in April and ends on the last Sunday in October. */
if year <= 2006 then do;
fdo_apr=intnx('month',fdoy,3);
dst_beg=intnx('week.1',fdo_apr,(weekday(fdo_apr) ne 1));
fdo_oct=intnx('month',fdoy,9);
dst_end=intnx('week.1',fdo_oct,(weekday(fdo_oct) in (6,7))+4);
end;
/* Due to the Energy Policy Act of 2005, Pub. L. no. 109-58, 119 Stat 594 */
/* (2005). Starting in March 2007, daylight time in the United States */
/* will begin on the second Sunday in March and end on the first Sunday */
/* in November. For more information, one reference is */
/* http://aa.usno.navy.mil */
else do;
fdo_mar=intnx('month',fdoy,2);
dst_beg=intnx('week.1',fdo_mar, (weekday(fdo_mar) in (2,3,4,5,6,7))+1);
fdo_nov=intnx('month',fdoy,10);
dst_end=intnx('week.1',fdo_nov,(weekday(fdo_nov) ne 1));
end;
put dst_beg= worddate. /
dst_end= worddate. / ;
end;
run;
OUTPUT to SAS log
dst_beg=April 2, 2006
dst_end=October 29, 2006
dst_beg=March 11, 2007
dst_end=November 4, 2007
dst_beg=March 9, 2008
dst_end=November 2, 2008
dst_beg=March 8, 2009
dst_end=November 1, 2009
Determine the start and end dates for daylight saving time for given years.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Functions ==> Date and Time
|
| Date Modified: | 2006-06-10 03:02:43 |
| Date Created: | 2004-09-30 14:09:09 |
Operating System and Release Information
| SAS System | Base SAS | All | 6.12 | n/a |