Date: Thu, 23 Dec 2004 14:27:07 -0800
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "David L. Cassell" <cassell.david@EPAMAIL.EPA.GOV>
Subject: Re: calcualte the sliding difference inside a group
Content-type: text/plain; charset=US-ASCII
Bogdan Mihai <strimbu@INTERCHANGE.UBC.CA> wrote:
> . . . . .
> and i want to create a new variable diff such that inside group a and
> for a=1 and b=x
> for c=1 : diff =int(d*ranuni(seed)); let say diff=15
> for c=2: diff = int((d-15)*ranuni(seed)); let say diff
> for c=3: diff=int(d-15-7)*ranuni(seed)); let say diff=0
> if diff <= 0 then diff = 23-15-7=1
> for c=4: diff=0; (this means that as soon diff became 0 all the rest
> the diffs are 0
> (in short I want a variable obtained as the difference between a
> value and a given number)
> . . . . .
I see that Chang has already supplied a nice algorithm.
You could do a similar approach using first.a to initialize
your sequences (assuming the data are sorted by b and then a,
as appears from the limited data).
My concern is different. *Why* are you building a sequence like
this? It looks like some sort of truncated time series. If we knew
what you were really trying to accomplish (the big picture, that is)
we might be able to help you more.
David Cassell, CSC
Senior computing specialist