Date: Fri, 1 Dec 2006 12:17:34 -0800
Reply-To: Leong <leongfin@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Leong <leongfin@GMAIL.COM>
Organization: http://groups.google.com
Subject: Re: count the length of a sequence of ones and zeros
In-Reply-To: <1164968331.256049.154140@f1g2000cwa.googlegroups.com>
Content-Type: text/plain; charset="us-ascii"
Thanks Frank, the ts are indeed observations, the code works perfectly
..
Frank Poppe wrote:
> If the data is organised in observations rather then in a string within
> observations, you can use the BY statement with the FIRST. construct
> like below.
>
> Frank Poppe
>
> data in ;
> input ts ;
> cards ;
> 1
> 1
> 0
> 0
> 0
> 1
> 1
> 1
> 1
> 1
> 0
> 0
> 0
> ;
>
> data runs ;
> set in ;
> by ts notsorted ;
> if first.ts then position = 0 ;
> if ts = 1 then position + 1 ;
> else position = . ;
> run ;
>
> ods listing ;
> proc print data = runs ;
> run ;
>
> Leong schreef:
>
> > Hi,
> >
> > I have a time sereis of ones and zeros, for instance
> > 11000111110001......
> > above sequence can be viewed as runs of ones and runs of zeros, that
> > is:
> >
> > first run: 1 1
> > second run 0 0 0 0
> > third run 11111
> > fourth run 0 0 0
> > ......
> >
> > I am only interested in the position of one in a given run.
> > I would like to have a SAS program that can tell me the position of
> > each one in all the runs ( the position of zeros can be treated as
> > either zero or misssing value)
> >
> > i.e.
> >
> > TS position
> >
> > 1 1
> > 1 2
> > 0 .
> > 0 .
> > 0 .
> > 1 1
> > 1 2
> > 1 3
> > 1 4
> > 1 5
> > 0 .
> > 0 .
> > 0 .
> > ...
> >
> > thanks a lot
> > Leong.
|