Date: Fri, 1 Dec 2006 10:42:56 -0500 Venky Chakravarthy "SAS(r) Discussion" Venky Chakravarthy Re: count the length of a sequence of ones and zeros To: Guido T

Hi Guido,

I looked at this and was wondering if an accumaltor variable would allow itself to be reset to missing and sure enough it worked.

data in ; input ts ; cards ; 1 1 0 0 0 1 1 1 1 1 0 0 0 ;

data out ; set in ; if ts = 1 then pos + 1 ; else pos = . ; run ;

Venky Chakravarthy

On Fri, 1 Dec 2006 11:54:20 +0000, Guido T <cymraegerict@GMAIL.COM> wrote:

>Hi Frank, > >thanks for reminding me about "BY xxx NOTSORTED", it's just come in >handy for a piece of code I'm working on. > >Any way, here's my RETAIN "solution" to the problem. > >data check; > set test; > retain position; > if ts then position = sum(position,1); > else position = .; >run; > >Regards >++ Guido > >On 01/12/06, Frank Poppe <Frank.Poppe@pwcons.com> 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. >>

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