Date: Mon, 31 Mar 2008 20:26:53 -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
Depends upon what is different betwee the various teams. For example, if
they all have the same start and end times as Team AA, except for Team BB,
you could get away with something as simple as:
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;
array closetimes(2,7) ('08:30't 5*'17:00't '8:30't,
'08:30't 5*'21:00't '8:30't);
Time_in_hrs = 0;
*format Time_in_hrs time5.;
do date = Received_date to Completed_date;
opentime = '08:30't;
group = ifn(Team='BB',2,1);
closetime = ifn(hdays(date),
opentime,
closetimes(group,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;
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.
HTH,
Art
--------
On Mon, 31 Mar 2008 20:18:06 -0400, Christine Harrison
<C.Harrison81@GMAIL.COM> wrote:
>Yes this is exactly what I need Arthur.
>
>Initially what I did was using if..then...do to split the teams up
>
>But this is a much better way to do it.
>
>My final question there is more than 2 teams so if I want more teams to be
>added what would I need to change in your code?? Say team CC, DD,
>EE...etc...
>
>Thank you very much for your assistance.
>
>Christine
>
>
>
>My if then do attempt
>
>data TeamA (keep = Team Received_date Received_time Completed_date
> 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;
>if Team='AA' then do;
>array _1closetimes(7) ('08:30't 5*'17:00't '8:30't);
>Time_in_hrs = 0;
> do date = Received_date to Completed_date;
> opentime = '08:30't;
> _1closetime = ifn(hdays(date),
> opentime,
> _1closetimes(weekday(date) ) );
> if not(hdays(date) or weekday(date) in (1,7)) then
> Time_in_hrs + _1closetime - opentime
> - (date = Received_date) * (Received_time - opentime)
> - (date = Completed_date) * (_1closetime - Completed_time);
> end;
> Time_in_hrs=Time_in_hrs/3600;
>end;
>
>if Team='BB' then do;
>array _2closetimes(7) ('08:30't 5*'21:00't '8:30't) ;
>Time_in_hrs = 0;
> do date = Received_date to Completed_date;
> opentime = '08:30't;
> _2closetime = ifn(hdays(date),
> opentime,
> _2closetimes(weekday(date) ) );
> if not(hdays(date) or weekday(date) in (1,7)) then
> Time_in_hrs + _2closetime - opentime
> - (date = Received_date) * (Received_time - opentime)
> - (date = Completed_date) * (_2closetime - Completed_time);
> end;
> Time_in_hrs=Time_in_hrs/3600;
>end;
>run;
|