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 (May 2008, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 30 May 2008 08:44:11 -0400
Reply-To:   Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Subject:   Re: How to create a rolling calculation in SAS?

what's the use of the variable OBS? Ok, you can try it like the following:

data input; input x; datalines; 3 4 7 9 10 20 1 9 11 1 ; run;

data result; set input; retain a1-a3; array e(*) a1-a3; e(1)=e(2); e(2)=e(3); e(3)=x; min=min(e(1),e(2),e(3)); max=max(e(1),e(2),e(3)); sum=sum(e(1),e(2),e(3)); drop a1-a3; run;

Gerhard

On Fri, 30 May 2008 04:11:15 -0700, andymanme@GOOGLEMAIL.COM wrote:

>Hi everyone, > >I am trying to produce a rolling calculation, every 3 observations >(but would like the ability to change this). > >Given an input dataset I want to look at a rolling observation window >(of say 3 records) and record against each observation what the >highest value was in the last 3 observations, the rolling sum and the >lowest value. > >Probably easier to give an example of what I am looking for: > >data input; > input obs x; >datalines; >1 3 >2 4 >3 7 >4 9 >5 10 >6 20 >7 1 >8 9 >9 11 >10 1 >; >run; >data required; > input obs x max_3 min_3 sum_3; >datalines; >1 3 . . . >2 4 3 3 3 >3 7 4 3 7 >4 9 7 3 14 >5 10 9 4 20 >6 20 10 7 26 >7 1 20 9 39 >8 9 20 1 31 >9 11 20 1 30 >10 1 11 1 21 >; >run; > >I have tried to put a lag calculation into a DO loop but haven?t been >able to work out how to go about this. > >Help gratefully received! >Andy


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