SAS date functions

  • Follow


Are there convenient SAS functions for finding, say, the last Sunday in
October (which is the first day of daylight saving time)?

0
Reply paulvonhippel (114) 6/8/2006 2:23:00 PM

On Thu, 8 Jun 2006 10:44:08 -0400, Venky Chakravarthy <swovcc@HOTMAIL.COM>
wrote:

>On Thu, 8 Jun 2006 07:23:00 -0700, Paul <paulvonhippel@YAHOO.COM> wrote:
>
>>Are there convenient SAS functions for finding, say, the last Sunday in
>>October (which is the first day of daylight saving time)?
>
>Start in November and work backwards with INTNX. We can look for specific
>days of the week using week.1 for Sunday through week.7 Saturday. WEEK.1 is
>the default when you specify WEEK.
>
>329  data _null_ ;
>330    daylight = intnx ( "week" , "01NOV2006"d , -1 ) ;
>331    put daylight= : weekdate. ;
>332  run ;
>
>daylight=Sunday, October 22, 2006
>
>Venky Chakravarthy

As data _null_ has demonstrated the first backward interval is 0 and not -1
that I have used above. Shows that I didn't even look at the result
carefully. A bad thing when posting in a public forum. I had the right idea
but implemented it wrong.

Venky Chakravarthy
0
Reply swovcc (585) 6/8/2006 3:03:35 PM


At bit more testing reveals that the enddate should be 31oct with
interval 0.  Or you get DLT ending on 01NOV in some years.

69   data _null_;
70      do year = 1990 to 2020;
71         dltB=intnx('WEEK',mdy(3,31,year),1);
72         dltE=intnx('WEEK',mdy(10,31,year),0);
73         put (dlt:) (=weekdate25.);
74         end;
75      run;

dltB=Sunday, Apr 1, 1990 dltE=Sunday, Oct 28, 1990
dltB=Sunday, Apr 7, 1991 dltE=Sunday, Oct 27, 1991
dltB=Sunday, Apr 5, 1992 dltE=Sunday, Oct 25, 1992
dltB=Sunday, Apr 4, 1993 dltE=Sunday, Oct 31, 1993


On 6/8/06, Venky Chakravarthy <swovcc@hotmail.com> wrote:
> On Thu, 8 Jun 2006 10:44:08 -0400, Venky Chakravarthy <swovcc@HOTMAIL.COM>
> wrote:
>
> >On Thu, 8 Jun 2006 07:23:00 -0700, Paul <paulvonhippel@YAHOO.COM> wrote:
> >
> >>Are there convenient SAS functions for finding, say, the last Sunday in
> >>October (which is the first day of daylight saving time)?
> >
> >Start in November and work backwards with INTNX. We can look for specific
> >days of the week using week.1 for Sunday through week.7 Saturday. WEEK.1 is
> >the default when you specify WEEK.
> >
> >329  data _null_ ;
> >330    daylight = intnx ( "week" , "01NOV2006"d , -1 ) ;
> >331    put daylight= : weekdate. ;
> >332  run ;
> >
> >daylight=Sunday, October 22, 2006
> >
> >Venky Chakravarthy
>
> As data _null_ has demonstrated the first backward interval is 0 and not -1
> that I have used above. Shows that I didn't even look at the result
> carefully. A bad thing when posting in a public forum. I had the right idea
> but implemented it wrong.
>
> Venky Chakravarthy
>
0
Reply datanull (3058) 6/8/2006 3:14:59 PM

Data _null_,
I noticed the same thing, but you fix is not reliable since it depends on the fact that November 1 is not a Sunday.  Use
        dltE=intnx('WEEK',mdy(11,1,year)-1,0);
to guarantee that it works for all years.
Ian Whitlock
==========================
Date:         Thu, 8 Jun 2006 10:56:37 -0400
Reply-To:     "data _null_;" <datanull@GMAIL.COM>
Sender:       "SAS(r) Discussion"
From:         "data _null_;" <datanull@GMAIL.COM>
Subject:      Re: SAS date functions
Comments: To: Paul <paulvonhippel@yahoo.com>
In-Reply-To:  <1149776580.739735.316230@i40g2000cwc.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Does this look right?  I know it is for 2006.

41   data _null_;
42      do year = 2004,2005,2006;
43         dltB=intnx('WEEK',mdy(3,31,year),1);
44         dltE=intnx('WEEK',mdy(11,1,year),0);
45         put (dlt:) (=weekdate25.);
46         end;
47      run;

dltB=Sunday, Apr 4, 2004 dltE=Sunday, Oct 31, 2004
dltB=Sunday, Apr 3, 2005 dltE=Sunday, Oct 30, 2005
dltB=Sunday, Apr 2, 2006 dltE=Sunday, Oct 29, 2006


On 6/8/06, Paul <paulvonhippel@yahoo.com> wrote:
> Are there convenient SAS functions for finding, say, the last Sunday in
> October (which is the first day of daylight saving time)?
>
0
Reply iw1junk (1195) 6/8/2006 3:18:01 PM

3 Replies
13 Views

(page loaded in 0.077 seconds)


Reply: