Ron Cody includes a SAS macro in several of his books. Premal Vora (2008) compares the DATA step to PROC EXPAND code in the paper "Easy Rolling Statistics with PROC EXPAND.".The SAS Knowledge Base provides the article "Compute the moving average of a variable.".If you do not have SAS/ETS software, the following references show how to use the SAS DATA step to compute simple moving averages by using the LAG function: You can also use transformation options to control how moving averages are defined for the first few data points.Ĭreate a moving average in SAS by using the DATA step In particular, you can use the METHOD= option to specify how to interpolate missing values. See the documentation for PROC EXPAND for various issues related to missing data. To keep this article as simple as possible, I have not discussed how to handle missing data when computing moving averages. Series x=t y=EWMA / name= 'EWMA' legendlabel= "EWMA(0.3)" Series x=t y=MA / name= 'MA' legendlabel= "MA(5)" The following call to PROC SGPOT creates the graph at the top of this article: This enables you to visualize short-term trends in the data. The METHOD=NONE options ensures that the raw data points are used to compute the moving averages, rather than interpolated values.Īn important use of a moving average is to overlay a curve on a scatter plot of the raw data. By default, the EXPAND procedure fits cubic spline curves to the nonmissing values of variables. Notice the METHOD=NONE option on the PROC EXPAND statement. Specifies that EWMA is an output variable that is an exponentially weighted moving average with parameter 0.3. The weights are automatically standardized by the procedure, so the formula is Specifies that WMA is an output variable that is a weighted moving average.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |