LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (March 2003, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 20 Mar 2003 13:50:44 -0500
Reply-To:   Howard_Schreier@ITA.DOC.GOV
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Howard_Schreier@ITA.DOC.GOV
Subject:   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