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 (April 1998, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 16 Apr 1998 19:04:08 +0100
Reply-To:     Peter Crawford <Peter@CRAWFORDSOFTWARE.DEMON.CO.UK>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Peter Crawford <Peter@CRAWFORDSOFTWARE.DEMON.CO.UK>
Organization: Crawford Software Consultancy Limited
Subject:      Re: Moveing Averages/MAVERAGE?

In article <1998Apr16.182020@vyh.fi>, Arjen Raateland <raateland@vyh.fi> writes >SAS-L'ers, > >I've been looking for a macro to do moving averages. The SAS Sample >library is supposed to contain a macro named MAVERAGE for this >purpose, but I cannot find it on our installation, nor on the SI web >pages or anywhere else I looked. > >I hope somebody out here knows if it exists and where I can find it or >another way to conveniently calculate moving averages without PROC >EXPAND! > >TIA, >--... ...-- -.. . --- .... ..--- --.. .- --.. >Arjen Raateland, SAS Support >Finnish Environment Institute >Helsinki, Finland >.-.-. -.- I hope this might help

%let depth=6; ** specifying length of the moving average group; array act_{&depth} _temporary_ ; i_ = mod( _n_, &depth ) +1 ; ** pointer into collection array; act_{ i_ } = thisval; ** store each value in the array; i_ = min( _n_, &depth ); ** first 5 obs average over _n_; mave_ = sum( of act_{*} ) / i_ ;

The reason I'm hesitant about making it into a macro is you must generate a unique array name the values may not come unique by datastep loop ( _n_ ) special handling may be required around by groups and the first &depth

Each instance is simpler in open code than coping with all these options in a macro.

-- Peter Crawford


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