| Date: | Thu, 8 Jun 2006 08:38:07 -0700 |
| Reply-To: | chris@OVIEW.CO.UK |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | chris@OVIEW.CO.UK |
| Organization: | http://groups.google.com |
| Subject: | Re: SAS date functions |
|
| In-Reply-To: | <200606081344.k58CjB5o001361@mailgw.cc.uga.edu> |
| Content-Type: | text/plain; charset="iso-8859-1" |
|---|
Venky, the last Sunday in October can never be the 22nd :-)
I was too slow, but here's my solution, avoiding the INTNX function,
which I've never used enough to be familiar with:
156 data _null_;
157 year = 2006;
158 lastsun = mdy(10, 31, year) - weekday(mdy(10, 31, year)) + 1;
159 put lastsun weekdate.;
160 run;
Sunday, October 29, 2006
And a more tricksy version which avoids needing to know how many days
each month has:
219 data _null_;
220 month = 12;
221 year = 2006;
222
223 month = month + 1;
224 if month = 13 then do;
225 year = year + 1;
226 month = 1;
227 end;
228 lastsun = mdy(month, 1, year) - weekday(mdy(month, 1, year)) +
1;
229
230
231 put lastsun weekdate.;
232 run;
Sunday, December 31, 2006
Chris.
--------------------------------------------------------
Elvis SAS Log Analyser - http://www.oview.co.uk/elvis
--------------------------------------------------------
Venky Chakravarthy 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
|