Date: Mon, 31 Mar 2008 21:07:38 -0400
Reply-To: Arthur Tabachneck <art297@NETSCAPE.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Arthur Tabachneck <art297@NETSCAPE.NET>
Subject: Re: HELP: How to fix up this code
Christine,
The following might suffice:
data test;
input Team $ (Received_date Received_time Completed_date Completed_time)(:
ddmmyy10. : time5.);
format Team $5. Received_date Completed_date date9. Received_time
Completed_time time5.;
cards;
AA 21/12/2007 10:00 27/12/2007 16:00
AA 20/03/2008 13:00 25/03/2008 11:30
AA 30/12/2007 13:00 31/12/2007 14:30
AA 24/01/2008 09:30 29/01/2008 12:30
AA 14/02/2008 11:30 20/02/2008 15:30
AA 14/03/2008 16:30 19/03/2008 13:30
AA 02/02/2008 12:00 06/02/2008 12:00
BB 21/12/2007 10:00 27/12/2007 16:00
BB 20/03/2008 13:00 25/03/2008 11:30
BB 30/12/2007 13:00 31/12/2007 14:30
BB 24/01/2008 09:30 29/01/2008 12:30
BB 14/02/2008 11:30 20/02/2008 15:30
BB 14/03/2008 16:30 19/03/2008 13:30
BB 02/02/2008 12:00 06/02/2008 12:00
; run;
data hdays;
input hday date9.;
datalines;
25DEC2007
26DEC2007
01JAN2008
26JAN2008
21MAR2008
24MAR2008
run;
proc format;
value $teamcode 'AA'=1
'BB'=2
'CC'=3
'DD'=4;
run;
data Teams (keep = Received_date Received_time Completed_date
Team
Completed_time
Time_in_hrs);
array hdays
(%sysfunc(mdy(1,1,2007) ):%sysfunc(mdy(12,31,2008) ) )
_temporary_;
if _n_=1 then do until (done);
set Hdays end=done;
hdays(hday) = 1;
end;
set test;
teamcode=put(team,teamcode.);
array closetimes(4,7) ('08:30't 5*'17:00't '8:30't,
'08:30't 5*'21:00't '8:30't,
'07:30't 5*'16:00't '7:30't,
'09:30't 5*'18:00't '9:30't);
Time_in_hrs = 0;
*format Time_in_hrs time5.;
do date = Received_date to Completed_date;
opentime = '08:30't;
closetime = ifn(hdays(date),
opentime,
closetimes(teamcode,weekday(date) ) );
if not(hdays(date) or weekday(date) in (1,7)) then
Time_in_hrs + closetime - opentime
- (date = Received_date) * (Received_time - opentime)
- (date = Completed_date) * (closetime - Completed_time);
end;
Time_in_hrs=Time_in_hrs/3600;
run;
Art
---------
On Mon, 31 Mar 2008 20:42:28 -0400, Christine Harrison
<C.Harrison81@GMAIL.COM> wrote:
>"If its not that simple, you could always use a format to recode Team and
>then expand the array to account for all of the teams"
>
>Sorry to bother you again but can you be so kind showing me how to do this
>Arthur?
>
>If say Team C have starting hour from 7:30am to 4:pm and Team D from
>9:30am to 6:00pm, how can I expand the array?
>
>Thank you Arthur.
>
>Christine
|