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
|