Date: Thu, 20 Mar 2003 13:50:44 -0500 Howard_Schreier@ITA.DOC.GOV "SAS(r) Discussion" Howard_Schreier@ITA.DOC.GOV Re: selecting consequent observations problem

Here is a DATA step solution.

First step: create two datasets, one (A) with the original data plus a sequence number (OBSNUM), the other with an indicator to mark points where a sequence starts or ends:

data a(keep = obsnum a) b(keep = obsnum b); set whatever; obsnum = _n_; output a; if a ne lag(a)+1 then do; b = 0; output b; count = 0; end; count ++ 1; if count=7 then do; obsnum = _n_ - 7 + 1; b = 1; output b; end; run;

Second step: combine the two and propagate the B values:

data result; update a b; by obsnum; drop obsnum b; rename bb = b; if b ne . then bb = b; retain bb; run;

I used UPDATE rather than MERGE because it handles one-to-many cases appropriately.

On Wed, 19 Mar 2003 17:32:31 -0500, Primak, Philip <Philip.Primak@GENZYME.COM> wrote:

>Dear SAS-L > >I have the following problem: >There is a data set with some numeric variable (let's say A) > Obs A > > 1 . > 2 1 > 3 2 > 4 2 > 5 3 > 6 4 > 7 5 > 8 6 > 9 7 > 10 8 > 11 8 > 12 9 > 13 99 > >I have to distinguish those observations, where A is consequent 7 numbers. >Another words I need to create variable B, which will be equal to 1 for >observations 4-10 and 0 otherwise. > >Any help is appreciated. > >thanks >Philip Primak >Genzyme Corp

Back to: Top of message | Previous page | Main SAS-L page