/* This program demonstrates the classical decomposition of a time series: Y = T + C + S + I where Y = time series to be described T = Trend C = Cycle S = Seasonal I = Irregular */ /* This segment of the program generates a Deterministic Trend. */ data mc1; do t = 1 to 100; tr = 100.0 + 4.0*t; output; end; keep tr t; proc gplot data=mc1; symbol v=dot c=black i=join h=.8; title1 'Deterministic Trend Data'; title2 'X=Time Y=Trend Series'; axis1 order=(0 to 100 by 10) label=(f=duplex 'Time'); axis2 order=(-100 to 700 by 100) label=(f=duplex 'Trend Series'); plot tr*t / haxis=axis1 vaxis=axis2; run; /* This segment of the program generates a Deterministic Cycle. */ data mc2; do t = 1 to 100; c = 50*cos(3.1416*t/10); output; end; keep c t; proc gplot data=mc2; symbol v=dot c=black i=join h=.8; title1 'Cycle with a=50, w = 2pi/20 (period = 20 months), theta = 0'; title2 'X=Time Y=Cyclical Series'; axis1 order=(0 to 100 by 10) label=(f=duplex 'Time'); axis2 order=(-150 to 150 by 30) label=(f=duplex 'Cycle'); plot c*t / haxis=axis1 vaxis=axis2; run; /* This segment of the program generates a Deterministic Seasonal. The Seasonal Effects add to one. */ data seasonal; input mon s; datalines; 1 -50 2 -25 3 25 4 -25 5 -50 6 50 7 75 8 50 9 5 10 -25 11 -50 12 20 ; proc gplot data=seasonal; symbol v=dot c=black i=join h=.8; title1 'Seasonal Effects by Month'; title2 'X=Time Y=Seasonal Effects'; axis1 order=(1 to 12 by 1) label=(f=duplex 'Time'); axis2 order=(-150 to 150 by 30) label=(f=duplex 'Seasonal Effects'); plot s*mon / haxis=axis1 vaxis=axis2; run; /* Setting up the seasonal effects and the seasonal dummy variables. */ data mc3; do t = 1 to 100; month = mod(t,12); if month = 0 then month = 12; if month = 1 then s = -50; if month = 2 then s = -25; if month = 3 then s = 25; if month = 4 then s = -25; if month = 5 then s = -50; if month = 6 then s = 50; if month = 7 then s = 75; if month = 8 then s = 50; if month = 9 then s = 5; if month = 10 then s = -25; if month = 11 then s = -50; if month = 12 then s = 20; if month = 2 then dum2 = 1; else dum2 = 0; if month = 3 then dum3 = 1; else dum3 = 0; if month = 4 then dum4 = 1; else dum4 = 0; if month = 5 then dum5 = 1; else dum5 = 0; if month = 6 then dum6 = 1; else dum6 = 0; if month = 7 then dum7 = 1; else dum7 = 0; if month = 8 then dum8 = 1; else dum8 = 0; if month = 9 then dum9 = 1; else dum9 = 0; if month = 10 then dum10 = 1; else dum10 = 0; if month = 11 then dum11 = 1; else dum11 = 0; if month = 12 then dum12 = 1; else dum12 = 0; output; end; run; title 'Seasonal Effects and Seasonal Dummy Variables'; proc print data = mc3; /* This segment of the program generates the Irregular Component. */ data mc4; do t = 1 to 100; i = 10*rannor(t); output; end; run; proc gplot data=mc4; symbol v=dot c=black i=join h=.8; title1 'Irregular Component'; title2 'X=Time Y=Irregular Component'; axis1 order=(0 to 100 by 10) label=(f=duplex 'Time'); axis2 order=(-150 to 150 by 30) label=(f=duplex 'Irregular Component'); plot i*t / haxis=axis1 vaxis=axis2; run; data combine; merge mc1 mc2 mc3 mc4; data combine; set combine; y1 = tr; y2 = tr + c; y3 = tr + c + s; y4 = tr + c + s + i; y5 = y4/100; z = exp(y5); logz = log(z); run; proc gplot data=combine; symbol v=dot c=black i=join h=.8; title1 'Exponential Growth Data'; title2 'X=Time Y=Exp Growth Data'; axis1 order=(0 to 100 by 10) label=(f=duplex 'Time'); axis2 order=(0 to 300 by 25) label=(f=duplex 'Exp Growth Data'); plot z*t / haxis=axis1 vaxis=axis2; run; proc gplot data=combine; symbol v=dot c=black i=join h=.8; title1 'Log Transform of Exponential Growth Data'; title2 'X=Time Y=Logged Data'; axis1 order=(0 to 100 by 10) label=(f=duplex 'Time'); axis2 order=(0 to 6 by 1) label=(f=duplex 'Logged Data'); plot logz*t / haxis=axis1 vaxis=axis2; run;