From: Ya on 9 Aug 2010 15:47 On Aug 9, 12:37 pm, William <shawfee....(a)gmail.com> wrote: > On Aug 9, 12:22 pm, Ya <huang8...(a)gmail.com> wrote: > > > > > > > > Ok, this should do it: > > > > data need; > > > set example; > > > retain flag0 startime; > > > if ^missing(index) then do; flag0=index; startime=time; end; > > > if type='B12' and time <= startime +5 then flag=flag0; > > > drop flag0; > > > run; > > > > proc print; > > > run; > > > > 23 23 B12 20030303 1301 934 > > > 3 . 913 . > > > 24 24 B11 20030303 1301 934 5 > > > 2 934 . > > > 25 25 B12 20030303 1301 934 > > > 6 . 934 2 > > > 26 26 B12 20030303 1301 935 > > > 1 . 934 2 > > > 27 27 B12 20030303 1301 936 > > > 1 . 934 2 > > > 28 28 B11 20030303 1301 937 > > > 1 . 934 . > > > 29 29 B12 20030303 1301 937 > > > 2 . 934 2 > > > 30 30 B12 20030303 1301 937 > > > 4 . 934 2 > > > 31 31 B11 20030303 1301 939 > > > 1 . 934 . > > > 32 32 B12 20030303 1301 939 > > > 2 . 934 2 > > > 33 33 B12 20030303 1301 955 > > > 1 . 934 . > > > 34 34 B11 20030303 1301 956 > > > 1 . 934 . > > > 35 35 B12 20030303 1301 956 > > > 2 . 934 . > > > 36 36 B11 20030303 1301 957 > > > 1 . 934 . > > > 37 37 B12 20030303 1301 957 > > > 2 . 934 . > > > 38 38 B12 20030303 1301 957 > > > 4 . 934 . > > > > HTH > > > > Ya > > > The way I calculated the time difference is not robust, depend on your > > data, we may have better option. > > Is you time a character or numeric? > > I want to the following five minutes data, include all of the > variables, such as, obs, type, coid, date, time, num, flag. > The time is character, I can transfer it into time format.- Hide quoted text - > > - Show quoted text - If your time var is already SAS time, then just change the code to: if type='B12' and time <= startime + 300 then flag=flag0; My code did not drop any of your original variables, so you should have all of them. If your time is character like 1003=10:03, then you have to convert it to SAS time var, something like: if length(time)=4 then timen=input(substr(time,1,2)||':'|| substr(3,2),time5.); else if length(time)=3 then timen=input(substr(1,1)||':'| \substr(2,2),time5.);
From: William on 9 Aug 2010 15:56 On Aug 9, 12:22 pm, Ya <huang8...(a)gmail.com> wrote: > > Ok, this should do it: > > > data need; > > set example; > > retain flag0 startime; > > if ^missing(index) then do; flag0=index; startime=time; end; > > if type='B12' and time <= startime +5 then flag=flag0; > > drop flag0; > > run; > > > proc print; > > run; > > > 23 23 B12 20030303 1301 934 > > 3 . 913 . > > 24 24 B11 20030303 1301 934 5 > > 2 934 . > > 25 25 B12 20030303 1301 934 > > 6 . 934 2 > > 26 26 B12 20030303 1301 935 > > 1 . 934 2 > > 27 27 B12 20030303 1301 936 > > 1 . 934 2 > > 28 28 B11 20030303 1301 937 > > 1 . 934 . > > 29 29 B12 20030303 1301 937 > > 2 . 934 2 > > 30 30 B12 20030303 1301 937 > > 4 . 934 2 > > 31 31 B11 20030303 1301 939 > > 1 . 934 . > > 32 32 B12 20030303 1301 939 > > 2 . 934 2 > > 33 33 B12 20030303 1301 955 > > 1 . 934 . > > 34 34 B11 20030303 1301 956 > > 1 . 934 . > > 35 35 B12 20030303 1301 956 > > 2 . 934 . > > 36 36 B11 20030303 1301 957 > > 1 . 934 . > > 37 37 B12 20030303 1301 957 > > 2 . 934 . > > 38 38 B12 20030303 1301 957 > > 4 . 934 . > > > HTH > > > Ya > > The way I calculated the time difference is not robust, depend on your > data, we may have better option. > Is you time a character or numeric? Ok, I see. It works. Yo do an excellent work. Thank you so much! -Xiaofei
First
|
Prev
|
Pages: 1 2 3 Prev: Estimating the value for the functional form of the variance Next: Need help--Cross Table |