Date: Tue, 18 Nov 2008 10:13:56 -0600
Reply-To: Mary <mlhoward@avalon.net>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Mary <mlhoward@AVALON.NET>
Subject: Re: Programming Counts
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
reply-type=original
This is a little long but seems to work- I'm looking at each minute and
turning on a flag for a bucket for that observation,
then get frequencies of each bucket using Proc Freq:
data set1;
informat depart time6. arrive time5.;
format depart hhmm6. arrive hhmm6.;
infile cards;
input id depart arrive;
cards;
1 08:50 09:30
2 06:23 06:51
3 12:34 13:01
4 15:08 15:15
;
run;
data set2;
set set1;
informat eight_thirty nine nine_thirty ten ten_thirty eleven eleven_thirty
twelve twelve_thirty 1.;
eight_thirty=0;
do i=depart to arrive;
if i >= '08:30't and i <= '8:59't then eight_thirty=1;
if i >= '09:00't and i <= '9:29't then nine=1;
if i >= '09:30't and i <= '9:59't then nine_thirty=1;
if i >= '10:00't and i <= '10:29't then ten=1;
if i >= '10:30't and i <= '10:59't then ten_thirty=1;
if i >= '11:00't and i <= '11:29't then eleven=1;
if i >= '11:30't and i <= '11:59't then eleven_thirty=1;
if i >= '12:00't and i <= '12:29't then twelve=1;
if i >= '12:30't and i <= '12:59't then twelve_thirty=1;
end;
drop i;
run;
proc freq data=set2;
tables eight_thirty nine nine_thirty ten ten_thirty eleven eleven_thirty
twelve twelve_thirty;
run;
-Mary
----- Original Message -----
From: Sid N
To: SAS-L@LISTSERV.UGA.EDU
Sent: Tuesday, November 18, 2008 8:47 AM
Subject: Programming Counts
I am looking for SAS programming help. I have a dataset in the following
format:
ID Departure_Time Arrival_Time
1 0850 0930
2 0623 0651
3 1234 1301
4 1508 1515
. . .
. . .
. . .
. . .
. . .
n x y
I would like to determine the cumulative count of flights in-air at
different half-hour time periods across a given day (from 00:01-00:30 to
23:31-24:00).
In the above dataset, for ID 1, I would like give a count of 1 for the time
periods 08:31-09:00 and 09:01-0930.
Similarly a count of one for:
06:01-06:30 and 06:31-07:00 -- ID 2
12:31-13:00 and 13:01-13:30 -- ID 3
15:01-15:30 -- ID 4
... and so on.
I would like the final output table to be in the following format:
Time Count
00:01-00:30 a
00:31-01:00 b
01:01-01:30 c
. .
. .
. .
23:31-24:00 n
I appreciate any suggestions in this regard. Thank you for your attention.
Sid