```Date: Thu, 23 Dec 2004 14:27:07 -0800 Reply-To: cassell.david@EPAMAIL.EPA.GOV Sender: "SAS(r) Discussion" From: "David L. Cassell" Subject: Re: calcualte the sliding difference inside a group In-Reply-To: <200412231737.iBNHb88f022804@listserv.cc.uga.edu> Content-type: text/plain; charset=US-ASCII Bogdan Mihai wrote: > . . . . . > and i want to create a new variable diff such that inside group a and b > > 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 =int(23-15)*0.9=7 > 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 of > the diffs are 0 > (in short I want a variable obtained as the difference between a previous > 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 -- David Cassell, CSC Cassell.David@epa.gov Senior computing specialist mathematical statistician ```

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