/* Simulate various types of time series data */ data sim; call streaminit(123); do t=1 to 1000; e = rand("Normal",0,1); /* White noise */ y_wn = e; /* Random walk */ if t=1 then y_rw = e; else y_rw = y_rwl + e; /* Random walk with drift */ if t=1 then y_drw = e; else y_drw = 0.0005*t + y_drwl + e; /* Reversion to mean */ if t=1 then y_rev = e; else y_rev = 0.9*y_revl + e; /* Specify time windows */ if t<300 then period=1; else if 300<=t<600 then period=2; else period=3; output; /* Generate lagged values */ y_rwl = y_rw; y_drwl = y_drw; y_revl = y_rev; end; label y_wn = "White noise" y_rw = "Random walk" y_drw = "Random walk with drift" y_rev = "Reversion to mean" t = "Time"; run; /* Generate plots of these variables */ proc sgplot data=sim; series x=t y=y_wn; refline 0 / lineattrs=(color=red thickness=4); run; proc sgplot data=sim; series x=t y=y_rw; refline 0 / lineattrs=(color=red thickness=4); run; proc sgplot data=sim; series x=t y=y_drw; run; proc sgplot data=sim; series x=t y=y_rev; refline 0 / lineattrs=(color=red thickness=4); run; /* Statistical properties */ proc means data=sim mean var; by period; var y_wn y_rw y_drw; run; /* First difference random walk */ data sim; set sim; y_rw_dif = dif(y_rw); label y_rw_dif = "First-differenced random walk"; run; proc sgplot data=sim; series x=t y=y_rw_dif / y2axis; series x=t y=y_rw / lineattrs=(thickness=3); refline 0 / lineattrs=(color=red thickness=4); run;