From: William on
data example:
obs type date id time number index
1 B11 20030303 1301 900 1
2 B12 20030303 1301 900 2
3 B12 20030303 1301 902 1
4 B12 20030303 1301 904 1
5 B11 20030303 1301 905 1
6 B12 20030303 1301 905 2
7 B12 20030303 1301 910 3
8 B12 20030303 1301 910 5
9 B12 20030303 1301 911 1
10 B12 20030303 1301 913 1
11 B11 20030303 1301 913 3 1
12 B12 20030303 1301 913 4
13 B12 20030303 1301 914 1
14 B11 20030303 1301 915 1
15 B12 20030303 1301 915 2
16 B12 20030303 1301 917 1
17 B12 20030303 1301 918 1
18 B12 20030303 1301 931 2
19 B12 20030303 1301 932 1
20 B11 20030303 1301 933 5
21 B12 20030303 1301 933 6
22 B12 20030303 1301 934 1
23 B12 20030303 1301 934 3
24 B11 20030303 1301 934 5 2
25 B12 20030303 1301 934 6
26 B12 20030303 1301 935 1
27 B12 20030303 1301 936 1
28 B11 20030303 1301 937 1
29 B12 20030303 1301 937 2
30 B12 20030303 1301 937 4
31 B11 20030303 1301 939 1
32 B12 20030303 1301 939 2
33 B12 20030303 1301 955 1
34 B11 20030303 1301 956 1
35 B12 20030303 1301 956 2
36 B11 20030303 1301 957 1
37 B12 20030303 1301 957 2
38 B12 20030303 1301 957 4
39 B11 20030303 1301 958 1 3
40 B12 20030303 1301 958 2
41 B11 20030303 1301 959 1

when type=B11 and index=1, time is 9:13, I want to get the following
five minutes observation and type=B12,

for example,
when type=B11 and index=1, time is 9:13, I want to get the following
five minutes observation, that is to say get the observation from 12,
13, 15, 16, 17 and have a varable flag equal index=1.

when type=B11 and index=2, time is 9:34, I want to get the following
five minutes observation, that is to say get the observation from 25,
26, 27, 29, 30, 32 and have a varable flag equal index=2. etc.

My data have millions of observation, different id, different date,
different time, different number, and the index has more 20,000. How
to solve this question?

Thank you so much!
-Xiaofei
From: Barry Schwarz on
Sort by type, date, and time.

Loop through observations.
When you reach one with an index of interest, compute the end
time of interest and retain the index value and end time. Also set a
flag indicating that index should be updated.
If the update flag is set, check the time against end time. When
less, update index. When not, reset the update flag.

On Sun, 8 Aug 2010 21:07:04 -0700 (PDT), William
<shawfee.unr(a)gmail.com> wrote:

>data example:
>obs type date id time number index
>1 B11 20030303 1301 900 1
>2 B12 20030303 1301 900 2
>3 B12 20030303 1301 902 1
>4 B12 20030303 1301 904 1
>5 B11 20030303 1301 905 1
>6 B12 20030303 1301 905 2
>7 B12 20030303 1301 910 3
>8 B12 20030303 1301 910 5
>9 B12 20030303 1301 911 1
>10 B12 20030303 1301 913 1
>11 B11 20030303 1301 913 3 1
>12 B12 20030303 1301 913 4
>13 B12 20030303 1301 914 1
>14 B11 20030303 1301 915 1
>15 B12 20030303 1301 915 2
>16 B12 20030303 1301 917 1
>17 B12 20030303 1301 918 1
>18 B12 20030303 1301 931 2
>19 B12 20030303 1301 932 1
>20 B11 20030303 1301 933 5
>21 B12 20030303 1301 933 6
>22 B12 20030303 1301 934 1
>23 B12 20030303 1301 934 3
>24 B11 20030303 1301 934 5 2
>25 B12 20030303 1301 934 6
>26 B12 20030303 1301 935 1
>27 B12 20030303 1301 936 1
>28 B11 20030303 1301 937 1
>29 B12 20030303 1301 937 2
>30 B12 20030303 1301 937 4
>31 B11 20030303 1301 939 1
>32 B12 20030303 1301 939 2
>33 B12 20030303 1301 955 1
>34 B11 20030303 1301 956 1
>35 B12 20030303 1301 956 2
>36 B11 20030303 1301 957 1
>37 B12 20030303 1301 957 2
>38 B12 20030303 1301 957 4
>39 B11 20030303 1301 958 1 3
>40 B12 20030303 1301 958 2
>41 B11 20030303 1301 959 1
>
>when type=B11 and index=1, time is 9:13, I want to get the following
>five minutes observation and type=B12,
>
>for example,
>when type=B11 and index=1, time is 9:13, I want to get the following
>five minutes observation, that is to say get the observation from 12,
>13, 15, 16, 17 and have a varable flag equal index=1.
>
>when type=B11 and index=2, time is 9:34, I want to get the following
>five minutes observation, that is to say get the observation from 25,
>26, 27, 29, 30, 32 and have a varable flag equal index=2. etc.
>
>My data have millions of observation, different id, different date,
>different time, different number, and the index has more 20,000. How
>to solve this question?
>
>Thank you so much!
>-Xiaofei

--
Remove del for email
From: William on
On Aug 9, 12:51 pm, Barry Schwarz <schwa...(a)dqel.com> wrote:
> Sort by type, date, and time.
>
> Loop through observations.  
>      When you reach one with an index of interest, compute the end
> time of interest and retain the index value and end time.  Also set a
> flag indicating that index should be updated.
>      If the update flag is set, check the time against end time.  When
> less, update index.  When not, reset the update flag.
>
> On Sun, 8 Aug 2010 21:07:04 -0700 (PDT), William
>
>
>
> <shawfee....(a)gmail.com> wrote:
> >data example:
> >obs     type    date             id        time number  index
> >1       B11     20030303        1301    900     1
> >2       B12     20030303        1301    900     2
> >3       B12     20030303        1301    902     1
> >4       B12     20030303        1301    904     1
> >5       B11     20030303        1301    905     1
> >6       B12     20030303        1301    905     2
> >7       B12     20030303        1301    910     3
> >8       B12     20030303        1301    910     5
> >9       B12     20030303        1301    911     1
> >10      B12     20030303        1301    913     1
> >11      B11     20030303        1301    913     3       1
> >12      B12     20030303        1301    913     4
> >13      B12     20030303        1301    914     1
> >14      B11     20030303        1301    915     1
> >15      B12     20030303        1301    915     2
> >16      B12     20030303        1301    917     1
> >17      B12     20030303        1301    918     1
> >18      B12     20030303        1301    931     2
> >19      B12     20030303        1301    932     1
> >20      B11     20030303        1301    933     5
> >21      B12     20030303        1301    933     6
> >22      B12     20030303        1301    934     1
> >23      B12     20030303        1301    934     3
> >24      B11     20030303        1301    934     5       2
> >25      B12     20030303        1301    934     6
> >26      B12     20030303        1301    935     1
> >27      B12     20030303        1301    936     1
> >28      B11     20030303        1301    937     1
> >29      B12     20030303        1301    937     2
> >30      B12     20030303        1301    937     4
> >31      B11     20030303        1301    939     1
> >32      B12     20030303        1301    939     2
> >33      B12     20030303        1301    955     1
> >34      B11     20030303        1301    956     1
> >35      B12     20030303        1301    956     2
> >36      B11     20030303        1301    957     1
> >37      B12     20030303        1301    957     2
> >38      B12     20030303        1301    957     4
> >39      B11     20030303        1301    958     1       3
> >40      B12     20030303        1301    958     2
> >41      B11     20030303        1301    959     1
>
> >when type=B11 and index=1, time is 9:13, I want to get the following
> >five minutes observation and type=B12,
>
> >for example,
> >when type=B11 and index=1, time is 9:13, I want to get the following
> >five minutes observation, that is to say get the observation from 12,
> >13, 15, 16, 17 and have a varable flag equal index=1.
>
> >when type=B11 and index=2, time is 9:34, I want to get the following
> >five minutes observation, that is to say get the observation from 25,
> >26, 27, 29, 30, 32 and have a varable flag equal index=2.  etc.
>
> >My data have millions of observation, different id, different date,
> >different time, different number, and the index has more 20,000. How
> >to solve this question?
>
> >Thank you so much!
> >-Xiaofei
>
> --
> Remove del for email

proc sort data=a; by type date time; run;

Then I do not know what to do, I do not understand it clearly. Can you
write down the program? Thanks.
-Xiaofei
From: Ya on
On Aug 8, 10:06 pm, William <shawfee....(a)gmail.com> wrote:
> On Aug 9, 12:51 pm, Barry Schwarz <schwa...(a)dqel.com> wrote:
>
>
>
>
>
> > Sort by type, date, and time.
>
> > Loop through observations.  
> >      When you reach one with an index of interest, compute the end
> > time of interest and retain the index value and end time.  Also set a
> > flag indicating that index should be updated.
> >      If the update flag is set, check the time against end time.  When
> > less, update index.  When not, reset the update flag.
>
> > On Sun, 8 Aug 2010 21:07:04 -0700 (PDT), William
>
> > <shawfee....(a)gmail.com> wrote:
> > >data example:
> > >obs     type    date             id        time number  index
> > >1       B11     20030303        1301    900     1
> > >2       B12     20030303        1301    900     2
> > >3       B12     20030303        1301    902     1
> > >4       B12     20030303        1301    904     1
> > >5       B11     20030303        1301    905     1
> > >6       B12     20030303        1301    905     2
> > >7       B12     20030303        1301    910     3
> > >8       B12     20030303        1301    910     5
> > >9       B12     20030303        1301    911     1
> > >10      B12     20030303        1301    913     1
> > >11      B11     20030303        1301    913     3       1
> > >12      B12     20030303        1301    913     4
> > >13      B12     20030303        1301    914     1
> > >14      B11     20030303        1301    915     1
> > >15      B12     20030303        1301    915     2
> > >16      B12     20030303        1301    917     1
> > >17      B12     20030303        1301    918     1
> > >18      B12     20030303        1301    931     2
> > >19      B12     20030303        1301    932     1
> > >20      B11     20030303        1301    933     5
> > >21      B12     20030303        1301    933     6
> > >22      B12     20030303        1301    934     1
> > >23      B12     20030303        1301    934     3
> > >24      B11     20030303        1301    934     5       2
> > >25      B12     20030303        1301    934     6
> > >26      B12     20030303        1301    935     1
> > >27      B12     20030303        1301    936     1
> > >28      B11     20030303        1301    937     1
> > >29      B12     20030303        1301    937     2
> > >30      B12     20030303        1301    937     4
> > >31      B11     20030303        1301    939     1
> > >32      B12     20030303        1301    939     2
> > >33      B12     20030303        1301    955     1
> > >34      B11     20030303        1301    956     1
> > >35      B12     20030303        1301    956     2
> > >36      B11     20030303        1301    957     1
> > >37      B12     20030303        1301    957     2
> > >38      B12     20030303        1301    957     4
> > >39      B11     20030303        1301    958     1       3
> > >40      B12     20030303        1301    958     2
> > >41      B11     20030303        1301    959     1
>
> > >when type=B11 and index=1, time is 9:13, I want to get the following
> > >five minutes observation and type=B12,
>
> > >for example,
> > >when type=B11 and index=1, time is 9:13, I want to get the following
> > >five minutes observation, that is to say get the observation from 12,
> > >13, 15, 16, 17 and have a varable flag equal index=1.
>
> > >when type=B11 and index=2, time is 9:34, I want to get the following
> > >five minutes observation, that is to say get the observation from 25,
> > >26, 27, 29, 30, 32 and have a varable flag equal index=2.  etc.
>
> > >My data have millions of observation, different id, different date,
> > >different time, different number, and the index has more 20,000. How
> > >to solve this question?
>
> > >Thank you so much!
> > >-Xiaofei
>
> > --
> > Remove del for email
>
> proc sort data=a; by type date time; run;
>
> Then I do not know what to do, I do not understand it clearly. Can you
> write down the program? Thanks.
> -Xiaofei- Hide quoted text -
>
> - Show quoted text -

data need;
set example;
retain flag0;
if ^missing(index) then do;
n_=0; flag0=index; end;
if type='B12' then n_+1;
if n_<=5 and type='B12' then flag=flag0;
drop flag0 n_;
run;

proc print;
run;

obs type date id time number index flag

1 B11 20030303 1301 900 1 . .
2 B12 20030303 1301 900 2 . .
3 B12 20030303 1301 902 1 . .
4 B12 20030303 1301 904 1 . .
5 B11 20030303 1301 905 1 . .
6 B12 20030303 1301 905 2 . .
7 B12 20030303 1301 910 3 . .
8 B12 20030303 1301 910 5 . .
9 B12 20030303 1301 911 1 . .
10 B12 20030303 1301 913 1 . .
11 B11 20030303 1301 913 3 1 .
12 B12 20030303 1301 913 4 . 1
13 B12 20030303 1301 914 1 . 1
14 B11 20030303 1301 915 1 . .
15 B12 20030303 1301 915 2 . 1
16 B12 20030303 1301 917 1 . 1
17 B12 20030303 1301 918 1 . 1
18 B12 20030303 1301 931 2 . .
19 B12 20030303 1301 932 1 . .
20 B11 20030303 1301 933 5 . .
21 B12 20030303 1301 933 6 . .
22 B12 20030303 1301 934 1 . .
23 B12 20030303 1301 934 3 . .
24 B11 20030303 1301 934 5 2 .
25 B12 20030303 1301 934 6 . 2
26 B12 20030303 1301 935 1 . 2
27 B12 20030303 1301 936 1 . 2
28 B11 20030303 1301 937 1 . .
29 B12 20030303 1301 937 2 . 2
30 B12 20030303 1301 937 4 . 2
31 B11 20030303 1301 939 1 . .
32 B12 20030303 1301 939 2 . .
33 B12 20030303 1301 955 1 . .
34 B11 20030303 1301 956 1 . .
35 B12 20030303 1301 956 2 . .
36 B11 20030303 1301 957 1 . .
37 B12 20030303 1301 957 2 . .
38 B12 20030303 1301 957 4 . .
39 B11 20030303 1301 958 1 3 .
40 B12 20030303 1301 958 2 . 3
41 B11 20030303 1301 959 1 . .

HTH

Ya
From: William on
On Aug 10, 12:23 am, Ya <huang8...(a)gmail.com> wrote:
> On Aug 8, 10:06 pm, William <shawfee....(a)gmail.com> wrote:
>
>
>
> > On Aug 9, 12:51 pm, Barry Schwarz <schwa...(a)dqel.com> wrote:
>
> > > Sort by type, date, and time.
>
> > > Loop through observations.  
> > >      When you reach one with an index of interest, compute the end
> > > time of interest and retain the index value and end time.  Also set a
> > > flag indicating that index should be updated.
> > >      If the update flag is set, check the time against end time.  When
> > > less, update index.  When not, reset the update flag.
>
> > > On Sun, 8 Aug 2010 21:07:04 -0700 (PDT), William
>
> > > <shawfee....(a)gmail.com> wrote:
> > > >data example:
> > > >obs     type    date             id        time number  index
> > > >1       B11     20030303        1301    900     1
> > > >2       B12     20030303        1301    900     2
> > > >3       B12     20030303        1301    902     1
> > > >4       B12     20030303        1301    904     1
> > > >5       B11     20030303        1301    905     1
> > > >6       B12     20030303        1301    905     2
> > > >7       B12     20030303        1301    910     3
> > > >8       B12     20030303        1301    910     5
> > > >9       B12     20030303        1301    911     1
> > > >10      B12     20030303        1301    913     1
> > > >11      B11     20030303        1301    913     3       1
> > > >12      B12     20030303        1301    913     4
> > > >13      B12     20030303        1301    914     1
> > > >14      B11     20030303        1301    915     1
> > > >15      B12     20030303        1301    915     2
> > > >16      B12     20030303        1301    917     1
> > > >17      B12     20030303        1301    918     1
> > > >18      B12     20030303        1301    931     2
> > > >19      B12     20030303        1301    932     1
> > > >20      B11     20030303        1301    933     5
> > > >21      B12     20030303        1301    933     6
> > > >22      B12     20030303        1301    934     1
> > > >23      B12     20030303        1301    934     3
> > > >24      B11     20030303        1301    934     5       2
> > > >25      B12     20030303        1301    934     6
> > > >26      B12     20030303        1301    935     1
> > > >27      B12     20030303        1301    936     1
> > > >28      B11     20030303        1301    937     1
> > > >29      B12     20030303        1301    937     2
> > > >30      B12     20030303        1301    937     4
> > > >31      B11     20030303        1301    939     1
> > > >32      B12     20030303        1301    939     2
> > > >33      B12     20030303        1301    955     1
> > > >34      B11     20030303        1301    956     1
> > > >35      B12     20030303        1301    956     2
> > > >36      B11     20030303        1301    957     1
> > > >37      B12     20030303        1301    957     2
> > > >38      B12     20030303        1301    957     4
> > > >39      B11     20030303        1301    958     1       3
> > > >40      B12     20030303        1301    958     2
> > > >41      B11     20030303        1301    959     1
>
> > > >when type=B11 and index=1, time is 9:13, I want to get the following
> > > >five minutes observation and type=B12,
>
> > > >for example,
> > > >when type=B11 and index=1, time is 9:13, I want to get the following
> > > >five minutes observation, that is to say get the observation from 12,
> > > >13, 15, 16, 17 and have a varable flag equal index=1.
>
> > > >when type=B11 and index=2, time is 9:34, I want to get the following
> > > >five minutes observation, that is to say get the observation from 25,
> > > >26, 27, 29, 30, 32 and have a varable flag equal index=2.  etc.
>
> > > >My data have millions of observation, different id, different date,
> > > >different time, different number, and the index has more 20,000. How
> > > >to solve this question?
>
> > > >Thank you so much!
> > > >-Xiaofei
>
> > > --
> > > Remove del for email
>
> > proc sort data=a; by type date time; run;
>
> > Then I do not know what to do, I do not understand it clearly. Can you
> > write down the program? Thanks.
> > -Xiaofei- Hide quoted text -
>
> > - Show quoted text -
>
> data need;
>  set example;
> retain flag0;
> if ^missing(index) then do;
>  n_=0; flag0=index; end;
> if type='B12' then n_+1;
> if n_<=5 and type='B12' then flag=flag0;
> drop flag0 n_;
> run;
>
> proc print;
> run;
>
>  obs    type      date       id     time    number    index    flag
>
>    1    B11     20030303    1301     900       1        .        .
>    2    B12     20030303    1301     900       2        .        .
>    3    B12     20030303    1301     902       1        .        .
>    4    B12     20030303    1301     904       1        .        .
>    5    B11     20030303    1301     905       1        .        .
>    6    B12     20030303    1301     905       2        .        .
>    7    B12     20030303    1301     910       3        .        .
>    8    B12     20030303    1301     910       5        .        .
>    9    B12     20030303    1301     911       1        .        .
>   10    B12     20030303    1301     913       1        .        .
>   11    B11     20030303    1301     913       3        1        .
>   12    B12     20030303    1301     913       4        .        1
>   13    B12     20030303    1301     914       1        .        1
>   14    B11     20030303    1301     915       1        .        .
>   15    B12     20030303    1301     915       2        .        1
>   16    B12     20030303    1301     917       1        .        1
>   17    B12     20030303    1301     918       1        .        1
>   18    B12     20030303    1301     931       2        .        .
>   19    B12     20030303    1301     932       1        .        .
>   20    B11     20030303    1301     933       5        .        .
>   21    B12     20030303    1301     933       6        .        .
>   22    B12     20030303    1301     934       1        .        .
>   23    B12     20030303    1301     934       3        .        .
>   24    B11     20030303    1301     934       5        2        .
>   25    B12     20030303    1301     934       6        .        2
>   26    B12     20030303    1301     935       1        .        2
>   27    B12     20030303    1301     936       1        .        2
>   28    B11     20030303    1301     937       1        .        .
>   29    B12     20030303    1301     937       2        .        2
>   30    B12     20030303    1301     937       4        .        2
>   31    B11     20030303    1301     939       1        .        .
>   32    B12     20030303    1301     939       2        .        .
>   33    B12     20030303    1301     955       1        .        .
>   34    B11     20030303    1301     956       1        .        .
>   35    B12     20030303    1301     956       2        .        .
>   36    B11     20030303    1301     957       1        .        .
>   37    B12     20030303    1301     957       2        .        .
>   38    B12     20030303    1301     957       4        .        .
>   39    B11     20030303    1301     958       1        3        .
>   40    B12     20030303    1301     958       2        .        3
>   41    B11     20030303    1301     959       1        .        .
>
> HTH
>
> Ya

Hi, You may do not see it clearly, I want the following five minutes
data, not the following five observation. Following you program, I try
many time to edit to meet my requirement, but it still did not work.
So could you make some change in the program?
Thanks.
-Xiaofei