Date: Thu, 10 Apr 2003 11:35:48 -0400
Reply-To: diskin.dennis@KENDLE.COM
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: diskin.dennis@KENDLE.COM
Subject: Re: first wednesday in October
Content-type: text/plain; charset=us-ascii
That's very useful Harry. How did you find the 'week.4' argument ?
SASHELP is pretty useless and the v8 online doc just says:
The value of the character constant or variable must be one of those listed in this table:
Date Intervals Datetime Intervals Time Intervals
DAY DTDAY HOUR
WEEKDAY DTWEEKDAY MINUTE
WEEK DTWEEK SECOND
TENDAY DTTENDAY
SEMIMONTH DTSEMIMONTH
MONTH DTMONTH
QTR DTQTR
SEMIYEAR DTSEMIYEAR
YEAR DTYEAR
Regards,
Dennis Diskin
From: "Droogendyk, Harry" <Harry.Droogendyk@CIBC.COM>@LISTSERV.UGA.EDU> on
04/10/2003 11:11 AM
Please respond to "Droogendyk, Harry" <Harry.Droogendyk@CIBC.COM>
Sent by: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
To: SAS-L@LISTSERV.UGA.EDU
cc:
Subject: Re: first wednesday in October
A succinct solution using the week.4 interval:
152 data _null_;
153 do year = 2000 to 2010;
154 oct1 = input('01oct' || put(year,4.),date9.);
155 first_wed = intnx('week.4',oct1,(4 ne weekday(oct1)));
156 put year @8 'First Wednesday is ' first_wed date9. ;
157 end;
158 run;
2000 First Wednesday is 04OCT2000
2001 First Wednesday is 03OCT2001
2002 First Wednesday is 02OCT2002
2003 First Wednesday is 01OCT2003
2004 First Wednesday is 06OCT2004
2005 First Wednesday is 05OCT2005
2006 First Wednesday is 04OCT2006
2007 First Wednesday is 03OCT2007
2008 First Wednesday is 01OCT2008
2009 First Wednesday is 07OCT2009
2010 First Wednesday is 06OCT2010
-----Original Message-----
From: Nigel Pain [mailto:Nigel.Pain@SCOTLAND.GSI.GOV.UK]
Sent: April 10, 2003 10:39 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: first wednesday in October
****************************************************************************
***************************************************************************
This email and any files transmitted with it are intended
solely for the use of the individual or entity to whom they are addressed.
****************************************************************************
***************************************************************************
The following code calculates the first Wednesday of
October
for ten years:
DATA _NULL_;
wednesday = 4;
october = 10;
DO year = 2000 TO 2010;
oct1_date = MDY(october,1,year);
oct1_day = WEEKDAY(oct1_date);
daydiff = wednesday - oct1_day + ((oct1_day
> wednesday ) *
7);
first_wed = INTNX("DAY",oct1_date,daydiff);
PUT first_wed= WEEKDATX. ;
END;
RUN;
The keys to this are the WEEKDAY function which returns the
week day of a
date as a number between 1 and 7 (where Sunday is 1 and so
Wednesday is 4)
and the INTNX function which advances a date by a specified
interval.
Given a year, you could condense this into a single line:
first_wed = INTNX("DAY",MDY(10,1,year),4 -
WEEKDAY(MDY(10,1,year)) +
((WEEKDAY(MDY(10,1,year)) > 4) * 7));
but the uncondensed code is probably easier to understand
and therefore
maintain.
***************************************************
Nigel Pain
Scottish Executive
Analytical Services Team
Victoria Quay
EDINBURGH
EH6 6QQ
UK
Tel +44 131 244 7237
Mailto:nigel.pain@scotland.gsi.gov.uk
Website: http:\\www.scotland.gov.uk
> -----Original Message-----
> From: Wim Goettsch [mailto:wim.goettsch@PHARMO.NL]
> Sent: 10 April 2003 13:21
> Subject: first wednesday in October
>
>
> Hello,
>
> I use a pharmacy dataset in which I have information on
prescription
> drugs including information on the start (dispensing) and
the duration
> of the prescription.
>
> In order to assess the point prevalence of use I need to
find out
> whether a patient 'used' the drugs on the first Wednesday
of October
> in every year. Until now I used a calender to select all
first
> Wednesdays in October, and transformed these dates in a
SAS date.
> Subsequently, I checked for every prescription whether
these dates
> were between the start and enddate of prescription.
>
> I am looking for a more convenient method to find out
whether a
> patient uses a drug on the first wednesday of October.
Does anybody
> have a suggestion?
>
> THANX, Wim
>