Skip to content

Instantly share code, notes, and snippets.

@statgeek
Created July 11, 2017 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save statgeek/07a3708dee1225ceb9d4aa75daab2c52 to your computer and use it in GitHub Desktop.
Save statgeek/07a3708dee1225ceb9d4aa75daab2c52 to your computer and use it in GitHub Desktop.
SAS Time Series Data - Fill time series with missing time points and calculate moving average
/*this is an example of time series data.
1. Create a time series data set with missing intervals (IBM)
2. Add back missing entries using PROC TIMESERIES (IBM_NO_MISSING)
3. Calculate moving average - 12 month average
*/
/*1*/
data ibm;
set sashelp.stocks;
where stock='IBM';
if month(date)=7 then
delete;
run;
proc sort data=ibm;
by date;
run;
/*2*/
proc timeseries data=ibm out=ibm_no_missing;
id date interval=month start='01Aug1986'd end='01Dec2005'd;
var open;
run;
/*3*/
proc expand data=ibm_no_missing out=want;
id date;
convert open = open_12 / method=none transformout= (movave 12);
run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment