|
It can be done in one step:
data halfhrs(drop = i);
set in1.roomdata;
array t[22];
do i = 1 to 22;
if st_time <= intnx('minute','06:30:00't,30*(i-1))
< end_time then t[i] = 1;
else t[i] = 0;
end;
u1=sum(of t1-t22); *--> entire day;
u2=sum(of t2-t4); *--> morning peak;
u3=sum(of t10-t12); *--> noon peak;
u4=sum(of t16-t18); *--> afternoon peak;
run;
Some other points ...
The indicator variables reflect the usage of the rooms at the half-hourly
boundary points rather than during the intervals.
I think I would use averages rather than sums so that measures for intervals
of different lengths can be directly compared.
On Wed, 15 Nov 2000 13:22:38 -0600, Kitzmann, Daniel J.
<kitzmann.daniel@MAYO.EDU> wrote:
>Hello SAS-L:
>
>I'm new to SAS-L (and for that matter, rather an amateur neophyte to SAS
>itself and programming in general), so please pardon this solicitation if
it
>proves over-elementary or otherwise inapt.
>
>The problem is thus: I have a dataset containing data with meeting-room
use.
>Each record represents a unique meeting that occurred and has variables as
>to the room identification, date of meeting, start time, and end time.
>(There are myriad other variables, but the foregoing four are the salient
>ones for my query here.)
>
>The desired result is to gauge room use across a variety of elements (mean
>daily use per room by hour of day, for instance). In other words, how much
>is a given room(s) used on any given day, as indicated by the data in the
>room-scheduling database? What percentage of the time, on average, is a
>room used between the hours of 11:30am and 12:30pm? Et cetera.
>
>After puzzling on it a while, my approach was to create for each
observation
>a series of time indicator variables, representing half-hour blocks of time
>associated with hours of the day. One advantage I saw in going through the
>pains of creating the myriad indicators -- as against merely summing
meeting
>durations (end_time - start_time) for each observation by date, room, etc.
>-- is that having a series of discrete variables will allow the graphical
>approximation of a continuous variable (time), whether by using PROC CHART
>or other utilities.
>
>In other words, I can easily create a histogram-like vertical bar graph
that
>would neatly depict room use by hour, thus showing which hours of the day a
>room experiences intensive use relative to other hours. There are a few
>other advantages, too, but I won't bother listing them.
>
>In any case, my code, as now written and which works, in part is as
follows:
>
>----
>* create SAS time values for half-hour increments of interest (i.e., from
> 6:30am to 5:30pm);
>
>data a1;
> do i=hms(6,30,0) to hms(17,30,0) by 1800;
> output;
> end;
>
>* transpose same values (observations) into variables;
>
>data a2(drop=i j);
> array t[22];
> do j=1 to 22;
> set a1;
> t[j]=i;
> end;
> link=1;
>
>* merge A2 with ROOMDATA (the dataset with room-use data) using arbitrary
>variable LINK, such that each obs. in ROOMDATA has the time-value constants
>created in A2;
>
>data roomdata;
> set in1.roomdata;
> link=1;
>
>proc sql;
> CREATE TABLE b1
> AS select *
> FROM a2 as x,
> roomdata as y
> WHERE x.link=y.link;
>quit;
>
>* create indicator variables for every obs. such that each half-hour
> increment in range (6:30, 7:00, 7:30, . . ., 17:30) is set as "on"
> (i.e., in-use) or "off" (not);
>
>data b2(drop=link i);
> set b1;
> array t[22];
> do i=1 to 22;
> if st_time<=t[i]<end_time then t[i]=1;
> else t[i]=0;
> end;
>
>* create variables that reflect sum of half-hours in use across
> selected time ranges of express interest;
>
> u1=sum(of t1-t22); *--> entire day;
> u2=sum(of t2-t4); *--> morning peak;
> u3=sum(of t10-t12); *--> noon peak;
> u4=sum(of t16-t18); *--> afternoon peak;
>
>run;
>---
>
>At this point, I can use PROC MEANS (or any variety of procs.) to generate
>the statistics of interest and graph them accordingly. My question is
>whether there is a more elegant, or at least concise, way to get the same
>result that my code does. For instance, can data steps A1 and A2 be
somehow
>combined into a single step achieving the same result? Or is there simply
>another conceptual way to create the time indicator variables?
>
>Again, the foregoing code "works", but it strikes me as long-winded
(perhaps
>not unlike the prose in this posting!) and possibly inefficient. Thanks
>molto for any criticism or instruction any of you may provide.
>
>Regards,
>Daniel Kitzmann
|