Date: Tue, 13 Apr 2004 21:20:19 -0700
Reply-To: kevin <kevin20142000@YAHOO.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: kevin <kevin20142000@YAHOO.COM>
Organization: http://groups.google.com
Subject: time comparing
Content-Type: text/plain; charset=ISO-8859-1
Hello all,
Three datasets need to have time comparing. The following condition
will be applied to the final dataset.
for each ID and time1,
1.time12=time2-time1 gt 0;
2.time13: if time3 le time1 then time13=time1-time3 gt 3;
if time3 gt time1 then time13=time3-time2 gt 0;
I have referred to subject "need some help" posted here on 3/31/04,
but I still could not think of a simple way to count events (time2) on
datasets b. The application here is after an event happened on dataset
a (time1), count events on dataset b (time2) with condition of no any
events(time3) happened 3hrs before time1 or between time1 and time2 on
datasets c. No events(time2) should be counted if the events(time2) do
not meet the above mentioned conditions. The time calculation is by id
and time1.
Any suggestion will be greatly appreciated.
Thanks in advance.
below are datasets:
data a;
input id adate : mmddyy8. atime : time8.;
format adate date9. atime time8.;
cards;
1 04/13/92 12:10:00
1 04/14/92 12:30:00
1 04/15/92 13:30:00
1 04/20/92 12:22:00
2 04/21/92 12:12:00
2 04/22/92 12:12:00
2 04/23/92 12:12:00
;
run;
data a;
set a;
time1=dhms(adate,0,0,atime);
run;
data b;
input id bdate : mmddyy8. btime : time8.;
format bdate date9. btime time8.;
cards;
1 04/13/92 12:12:00
1 04/14/92 11:10:00
1 04/14/92 11:30:00
1 04/15/92 12:00:00
1 04/15/92 14:00:00
1 04/20/92 11:10:00
2 04/21/92 11:10:00
2 04/22/92 11:10:00
2 04/23/92 13:10:00
;
run;
data b;
set b;
time2=dhms(bdate,0,0,btime);
run;
data c;
input id cdate : mmddyy8. ctime : time8.;
format cdate date9. ctime time8.;
cards;
1 04/13/92 11:12:00
1 04/14/92 13:10:00
1 04/15/92 11:30:00
1 04/15/92 16:00:00
1 04/20/92 11:10:00
2 04/22/92 11:20:00
2 04/23/92 13:10:00
;
run;
data c;
set c;
time3=dhms(cdate,0,0,ctime);
run;
data abc;
set a (in=a)
b (rename=(bdate=adate btime=atime) in=b)
c (rename=(cdate=adate ctime=atime) in=c)
;
if a then frm='A';
if b then frm='B';
if c then frm='C';
dtm=dhms(adate,0,0,atime);
run;
proc sort;
by id dtm;
run;