/*------------------------------------------------------------------*/ /* SAMPLE CODE */ /* SAS/ETS User's Guide, Version 6, Second Edition */ /* Publication book code: 56010 */ /* */ /* Each sample begins with a comment that states the */ /* chapter and page number where the code is located. */ /*------------------------------------------------------------------*/ /* Example 3.1 Simulated IMA Model */ /* Chapter 3 page 159 */ title1 'Simulated IMA(1,1) Series'; data a; u1 = 0.9; a1 = 0; do i = -50 to 100; a = rannor( 32565 ); u = u1 + a - .8 * a1; if i > 0 then output; a1 = a; u1 = u; end; run; proc arima data=a; identify var=u nlag=15; run; identify var=u(1) nlag=15; run; estimate q=1 ; run; quit; /* Example 3.2 Seasonal Model for the Airline Series */ /* Chapter 3 page 164 */ title1 'International Airline Passengers'; title2 '(Box and Jenkins Series-G)'; data seriesg; input x @@; xlog = log( x ); date = intnx( 'month', '31dec1948'd, _n_ ); format date monyy.; cards; 112 118 132 129 121 135 148 148 136 119 104 118 115 126 141 135 125 149 170 170 158 133 114 140 145 150 178 163 172 178 199 199 184 162 146 166 171 180 193 181 183 218 230 242 209 191 172 194 196 196 236 235 229 243 264 272 237 211 180 201 204 188 235 227 234 264 302 293 259 229 203 229 242 233 267 269 270 315 364 347 312 274 237 278 284 277 317 313 318 374 413 405 355 306 271 306 315 301 356 348 355 422 465 467 404 347 305 336 340 318 362 348 363 435 491 505 404 359 310 337 360 342 406 396 420 472 548 559 463 407 362 405 417 391 419 461 472 535 622 606 508 461 390 432 ; symbol1 i=join v=star; proc gplot data=seriesg; plot x * date = 1 / haxis= '1jan49'd to '1jan61'd by year; run; /* Example 3.2 continued page 165 */ proc arima data=seriesg; identify var=xlog(1,12) nlag=15; run; estimate q=(1)(12) noconstant method=uls; run; forecast out=b lead=24 id=date interval=month noprint; quit; /* Example 3.2 continued page 167 */ data c; set b; x = exp( xlog ); forecast = exp( forecast + std*std/2 ); l95 = exp( l95 ); u95 = exp( u95 ); run; /* Example 3.2 continued page 168 */ symbol1 i=none v=star; symbol2 i=join v=plus; symbol3 i=join v=none l=3; proc gplot data=c; where date >= '1jan58'd; plot x * date = 1 forecast * date = 2 l95 * date = 3 u95 * date = 3 / overlay haxis= '1jan58'd to '1jan62'd by year; run; /* Example 3.3 Model for Series J Data from Box and Jenkins */ /* Chapter 3 page 169 */ title1 'Gas Furnace Data'; title2 '(Box and Jenkins, Series J)'; data seriesj; input x y @@; label x = 'Input Gas Rate' y = 'Output CO2'; cards; -0.109 53.8 0.000 53.6 0.178 53.5 0.339 53.5 0.373 53.4 0.441 53.1 0.461 52.7 0.348 52.4 0.127 52.2 -0.180 52.0 -0.588 52.0 -1.055 52.4 -1.421 53.0 -1.520 54.0 -1.302 54.9 -0.814 56.0 -0.475 56.8 -0.193 56.8 0.088 56.4 0.435 55.7 0.771 55.0 0.866 54.3 0.875 53.2 0.891 52.3 0.987 51.6 1.263 51.2 1.775 50.8 1.976 50.5 1.934 50.0 1.866 49.2 1.832 48.4 1.767 47.9 1.608 47.6 1.265 47.5 0.790 47.5 0.360 47.6 0.115 48.1 0.088 49.0 0.331 50.0 0.645 51.1 0.960 51.8 1.409 51.9 2.670 51.7 2.834 51.2 2.812 50.0 2.483 48.3 1.929 47.0 1.485 45.8 1.214 45.6 1.239 46.0 1.608 46.9 1.905 47.8 2.023 48.2 1.815 48.3 0.535 47.9 0.122 47.2 0.009 47.2 0.164 48.1 0.671 49.4 1.019 50.6 1.146 51.5 1.155 51.6 1.112 51.2 1.121 50.5 1.223 50.1 1.257 49.8 1.157 49.6 0.913 49.4 0.620 49.3 0.255 49.2 -0.280 49.3 -1.080 49.7 -1.551 50.3 -1.799 51.3 -1.825 52.8 -1.456 54.4 -0.944 56.0 -0.570 56.9 -0.431 57.5 -0.577 57.3 -0.960 56.6 -1.616 56.0 -1.875 55.4 -1.891 55.4 -1.746 56.4 -1.474 57.2 -1.201 58.0 -0.927 58.4 -0.524 58.4 0.040 58.1 0.788 57.7 0.943 57.0 0.930 56.0 1.006 54.7 1.137 53.2 1.198 52.1 1.054 51.6 0.595 51.0 -0.080 50.5 -0.314 50.4 -0.288 51.0 -0.153 51.8 -0.109 52.4 -0.187 53.0 -0.255 53.4 -0.229 53.6 -0.007 53.7 0.254 53.8 0.330 53.8 0.102 53.8 -0.423 53.3 -1.139 53.0 -2.275 52.9 -2.594 53.4 -2.716 54.6 -2.510 56.4 -1.790 58.0 -1.346 59.4 -1.081 60.2 -0.910 60.0 -0.876 59.4 -0.885 58.4 -0.800 57.6 -0.544 56.9 -0.416 56.4 -0.271 56.0 0.000 55.7 0.403 55.3 0.841 55.0 1.285 54.4 1.607 53.7 1.746 52.8 1.683 51.6 1.485 50.6 0.993 49.4 0.648 48.8 0.577 48.5 0.577 48.7 0.632 49.2 0.747 49.8 0.900 50.4 0.993 50.7 0.968 50.9 0.790 50.7 0.399 50.5 -0.161 50.4 -0.553 50.2 -0.603 50.4 -0.424 51.2 -0.194 52.3 -0.049 53.2 0.060 53.9 0.161 54.1 0.301 54.0 0.517 53.6 0.566 53.2 0.560 53.0 0.573 52.8 0.592 52.3 0.671 51.9 0.933 51.6 1.337 51.6 1.460 51.4 1.353 51.2 0.772 50.7 0.218 50.0 -0.237 49.4 -0.714 49.3 -1.099 49.7 -1.269 50.6 -1.175 51.8 -0.676 53.0 0.033 54.0 0.556 55.3 0.643 55.9 0.484 55.9 0.109 54.6 -0.310 53.5 -0.697 52.4 -1.047 52.1 -1.218 52.3 -1.183 53.0 -0.873 53.8 -0.336 54.6 0.063 55.4 0.084 55.9 0.000 55.9 0.001 55.2 0.209 54.4 0.556 53.7 0.782 53.6 0.858 53.6 0.918 53.2 0.862 52.5 0.416 52.0 -0.336 51.4 -0.959 51.0 -1.813 50.9 -2.378 52.4 -2.499 53.5 -2.473 55.6 -2.330 58.0 -2.053 59.5 -1.739 60.0 -1.261 60.4 -0.569 60.5 -0.137 60.2 -0.024 59.7 -0.050 59.0 -0.135 57.6 -0.276 56.4 -0.534 55.2 -0.871 54.5 -1.243 54.1 -1.439 54.1 -1.422 54.4 -1.175 55.5 -0.813 56.2 -0.634 57.0 -0.582 57.3 -0.625 57.4 -0.713 57.0 -0.848 56.4 -1.039 55.9 -1.346 55.5 -1.628 55.3 -1.619 55.2 -1.149 55.4 -0.488 56.0 -0.160 56.5 -0.007 57.1 -0.092 57.3 -0.620 56.8 -1.086 55.6 -1.525 55.0 -1.858 54.1 -2.029 54.3 -2.024 55.3 -1.961 56.4 -1.952 57.2 -1.794 57.8 -1.302 58.3 -1.030 58.6 -0.918 58.8 -0.798 58.8 -0.867 58.6 -1.047 58.0 -1.123 57.4 -0.876 57.0 -0.395 56.4 0.185 56.3 0.662 56.4 0.709 56.4 0.605 56.0 0.501 55.2 0.603 54.0 0.943 53.0 1.223 52.0 1.249 51.6 0.824 51.6 0.102 51.1 0.025 50.4 0.382 50.0 0.922 50.0 1.032 52.0 0.866 54.0 0.527 55.1 0.093 54.5 -0.458 52.8 -0.748 51.4 -0.947 50.8 -1.029 51.2 -0.928 52.0 -0.645 52.8 -0.424 53.8 -0.276 54.5 -0.158 54.9 -0.033 54.9 0.102 54.8 0.251 54.4 0.280 53.7 0.000 53.3 -0.493 52.8 -0.759 52.6 -0.824 52.6 -0.740 53.0 -0.528 54.3 -0.204 56.0 0.034 57.0 0.204 58.0 0.253 58.6 0.195 58.5 0.131 58.3 0.017 57.8 -0.182 57.3 -0.262 57.0 ; proc arima data=seriesj; /*--- Look at the input process -------------------*/ identify var=x nlags=10; run; /*--- Fit a model for the input -------------------*/ estimate p=3; run; /*--- Crosscorrelation of prewhitened series ------*/ identify var=y crosscorr=(x) nlags=10; run; /*--- Fit transfer function - look at residuals ---*/ estimate input=( 3$ (1,2)/(1,2) x ) plot; run; /*--- Estimate full model -------------------------*/ estimate p=2 input=( 3$ (1,2)/(1) x ); run; quit; /* Example 3.4 An Intervention Model for Ozone Date */ /* Chapter 3 page 177*/ title1 'Intervention Data for Ozone Concentration'; title2 '(Box and Tiao, JASA 1975 P.70)'; data air; input ozone @@; label ozone = 'Ozone Concentration' x1 = 'Intervention for post 1960 period' summer = 'Summer Months Intervention' winter = 'Winter Months Intervention'; date = intnx( 'month', '31dec54'd, _n_ ); format date monyy.; month = month( date ); year = year( date ); x1 = year >= 1960; summer = ( 5 < month < 11 ) * ( year > 1965 ); winter = ( year > 1965 ) - summer; cards; 2.7 2.0 3.6 5.0 6.5 6.1 5.9 5.0 6.4 7.4 8.2 3.9 4.1 4.5 5.5 3.8 4.8 5.6 6.3 5.9 8.7 5.3 5.7 5.7 3.0 3.4 4.9 4.5 4.0 5.7 6.3 7.1 8.0 5.2 5.0 4.7 3.7 3.1 2.5 4.0 4.1 4.6 4.4 4.2 5.1 4.6 4.4 4.0 2.9 2.4 4.7 5.1 4.0 7.5 7.7 6.3 5.3 5.7 4.8 2.7 1.7 2.0 3.4 4.0 4.3 5.0 5.5 5.0 5.4 3.8 2.4 2.0 2.2 2.5 2.6 3.3 2.9 4.3 4.2 4.2 3.9 3.9 2.5 2.2 2.4 1.9 2.1 4.5 3.3 3.4 4.1 5.7 4.8 5.0 2.8 2.9 1.7 3.2 2.7 3.0 3.4 3.8 5.0 4.8 4.9 3.5 2.5 2.4 1.6 2.3 2.5 3.1 3.5 4.5 5.7 5.0 4.6 4.8 2.1 1.4 2.1 2.9 2.7 4.2 3.9 4.1 4.6 5.8 4.4 6.1 3.5 1.9 1.8 1.9 3.7 4.4 3.8 5.6 5.7 5.1 5.6 4.8 2.5 1.5 1.8 2.5 2.6 1.8 3.7 3.7 4.9 5.1 3.7 5.4 3.0 1.8 2.1 2.6 2.8 3.2 3.5 3.5 4.9 4.2 4.7 3.7 3.2 1.8 2.0 1.7 2.8 3.2 4.4 3.4 3.9 5.5 3.8 3.2 2.3 2.2 1.3 2.3 2.7 3.3 3.7 3.0 3.8 4.7 4.6 2.9 1.7 1.3 1.8 2.0 2.2 3.0 2.4 3.5 3.5 3.3 2.7 2.5 1.6 1.2 1.5 2.0 3.1 3.0 3.5 3.4 4.0 3.8 3.1 2.1 1.6 1.3 . . . . . . . . . . . . ; /* Example 3.4 continued page 178 */ proc arima data=air; /*--- Identify and seasonally difference ozone series ---*/ identify var=ozone(12) crosscorr=( x1(12) summer winter ) noprint; /*--- Fit a multiple regression with a seasonal MA model ---*/ /*--- by the maximum likelihood method ---*/ estimate q=(1)(12) input=( x1 summer winter ) noconstant method=ml itprint; /*--- Forecast ---*/ forecast lead=12 id=date interval=month; run; quit; /* Examples of Autocorrelated Data */ /* Chapter 4 page 187 */ data a; ul = 0; ull = 0; do time = -10 to 36; u = + 1.3 * ul - .5 * ull + 2*rannor(12346); y = 10 + .5 * time + u; if time > 0 then output; ull = ul; ul = u; end; run; /* Chapter 4 page 188 */ title "Autocorrelated Time Series"; proc gplot data=a; symbol1 v=star i=join; symbol2 v=none i=r; plot y * time = 1 y * time = 2 / overlay; run; /* Chapter 4 page 189 */ proc autoreg data=a; model y = time; run; /* Chapter 4 page 190 */ proc autoreg data=a; model y = time / nlag=2 method=ml; run; /* Chapter 4 page 192 */ proc autoreg data=a; model y = time / nlag=2 method=ml; output out=p p=yhat pm=trendhat; run; title "Predictions for Autocorrelation Model"; proc gplot data=p; symbol1 v=star i=none; symbol2 v=plus i=join; symbol3 v=none i=join; plot y * time = 1 yhat * time = 2 trendhat * time = 3 / overlay ; run; /* Forecasting Autoregressive Error Models */ /* Chapter 4 page 193 */ title "Forecasting Autocorrelated Time Series"; data b; y = .; do time = 37 to 46; output; end; run; data b; merge a b; by time; run; proc autoreg data=b; model y = time / nlag=2 method=ml; output out=p p=yhat pm=ytrend lcl=lcl ucl=ucl; run; proc gplot data=p; plot y*time=1 yhat*time=2 ytrend*time=3 lcl*time=3 ucl*time=3 / overlay href=36.5; where time >= 16; symbol1 v=star i=none; symbol2 v=plus i=join; symbol3 v=none i=join; run; /* Testing for Heteroscedasticity */ /* Chapter 4 page 199 */ data a; ul = 0; ull = 0; do time = -10 to 120; s = 1 + (time >= 60 & time < 90); u = + 1.3 * ul - .5 * ull + s*rannor(12346); y = 10 + .5 * time + u; if time > 0 then output; ull = ul; ul = u; end; run; title "Heteroscedastic Autocorrelated Time Series"; proc gplot data=a; symbol1 v=star i=join; symbol2 v=none i=r; plot y * time = 1 y * time = 2 / overlay; run; proc autoreg data=a; model y = time / nlag=2 archtest dwprob; output out=r r=yresid; run; proc autoreg data=a; model y = time / nlag=2 garch=(q=1,p=1) maxit=50; output out=out cev=vhat; run; /* Heteroscedasticity and GARCH Models */ /* Chapter 4 page 202 */ data out; set out; shat = sqrt( vhat ); run; title "Predicted and Actual Standard Deviations"; proc gplot data=out; plot s*time=1 shat*time=2 / overlay; symbol1 v=star i=none; symbol2 v=none i = join; run; /* Example 4.1 Analysis of Real Output Series */ /* Chapter 4 page 232 */ title 'Analysis of Real GNP'; data gnp; date = intnx( 'year', '01jan01'd, _n_-1 ); format date year4.; input x @@; y = log(x); dy = dif(y); t = _n_; label y = 'Real GNP' dy = 'First Difference of Y' t = 'Time Trend'; cards; 137.87 139.13 146.10 144.21 155.04 172.97 175.61 161.22 180.93 185.98 191.90 201.51 203.38 195.96 193.63 208.19 211.43 244.33 228.99 214.22 199.94 229.54 254.09 256.39 276.03 291.81 293.27 296.22 315.69 285.52 263.46 227.04 222.13 239.09 260.04 295.54 310.16 296.75 319.83 344.16 400.40 461.80 531.66 569.13 560.17 478.28 470.39 489.74 492.24 534.57 579.17 600.63 623.46 615.64 657.37 671.72 683.57 680.88 721.72 737.01 756.59 800.29 832.20 875.96 929.00 984.62 1011.38 1058.06 1087.58 1085.58 1122.42 1185.92 1254.20 1246.30 1231.61 1298.20 1369.71 1438.55 1479.44 1474.98 1512.15 1479.98 1534.68 ; proc gplot data=gnp; plot y * date / haxis='01jan01'd '01jan11'd '01jan21'd '01jan31'd '01jan41'd '01jan51'd '01jan61'd '01jan71'd '01jan81'd '01jan91'd; symbol i=join; run; /* Example 4.1 continued page 233 */ proc autoreg data=gnp; model y = t / nlag=2 method=ml; run; /* Example 4.1 continued page 235 */ %dftest(gnp,y,trend=2,outstat=stat1) proc print data=stat1; run; proc autoreg data=gnp; model dy = / nlag=1 method=ml; run; /* Example 4.2 Comparing Estimates and Model */ /* Chapter 4 page 236 */ title 'Grunfeld''s Investment Models Fit with Autoregressive Errors'; data grunfeld; input year gei gef gec; label gei = 'Gross investment GE' gec = 'Lagged Capital Stock GE' gef = 'Lagged Value of GE shares'; cards; 1935 33.1 1170.6 97.8 1936 45.0 2015.8 104.4 1937 77.2 2803.3 118.0 1938 44.6 2039.7 156.2 1939 48.1 2256.2 172.6 1940 74.4 2132.2 186.6 1941 113.0 1834.1 220.9 1942 91.9 1588.0 287.8 1943 61.3 1749.4 319.9 1944 56.8 1687.2 321.3 1945 93.6 2007.7 319.6 1946 159.9 2208.3 346.0 1947 147.2 1656.7 456.4 1948 146.3 1604.4 543.4 1949 98.3 1431.8 618.3 1950 93.5 1610.5 647.4 1951 135.2 1819.4 671.3 1952 157.3 2079.7 726.1 1953 179.5 2371.6 800.3 1954 189.6 2759.9 888.9 ; proc autoreg data=grunfeld; model gei = gef gec / nlag=1 dwprob; model gei = gef gec / nlag=1 method=uls; model gei = gef gec / nlag=1 method=ml; run; /* Example 4.3 Lack of Fit Study */ /* Chapter 4 page 239 */ title1 'Lack of Fit Study'; title2 'Fitting White Noise Plus Autoregressive Errors to a Sine Wave'; data a; pi=3.14159; do time = 1 to 75; if time > 75 then y = .; else y = sin( pi * ( time / 50 ) ); x = ranuni( 1234567 ); output; end; run; proc autoreg data=a; model y = x / nlag=1; output out=b p=pred pm=xbeta; run; proc gplot data=b; plot y*time=1 pred*time=2 xbeta*time=3 / overlay; symbol1 v='none' i=spline; symbol2 v='X'; symbol3 v=plus; run; /* Example 4.4 Missing Values */ /* Chapter 4 page 241 */ title 'Simulated Time Series with Roots:'; title2 ' (X-1.25)(X**4-1.25)'; title3 'With 15% Missing Values'; data ar; do i=1 to 550; e = rannor(12345); n = sum( e, .8*n1, .8*n4, -.64*n5 ); /* ar process */ y = n; if ranuni(7890) > .85 then y = .; /* 15% missing */ n5=n4; n4=n3; n3=n2; n2=n1; n1=n; /* set lags */ if i>500 then output; end; run; /* Example 4.4 continued page 242 */ proc autoreg data=ar partial; model y = / nlag=(1 4 5) method=ml; output out=a predicted=p residual=r ucl=u lcl=l alphacli=.01; run; /* Example 4.4 continued page 243 */ data reshape1; set a; miss = .; if r=. then do; miss = p; p = .; end; run; title 'Predicted Values and Confidence Limits'; proc gplot data=reshape1; plot l*i=1 miss*i=2 p*i=3 u*i=4 / overlay; symbol1 i=join v=none l=2; symbol2 i=needle v='X'; symbol3 i=needle v=circle; symbol4 i=join v=none l=2; run; /* Example 4.5 Money Demand Model */ /* Chapter 4 page 244 */ data money; date = intnx( 'qtr', '01jan1968'd, _n_-1 ); format date yyqc6.; input m1 gnp gdf ycb @@; m = log( 100 * m1 / gdf ); m1cp = log( 100 * lag(m1) / gdf ); y = log( gnp ); intr = log( ycb ); infr = 100 * log( gdf / lag(gdf) ); label m = 'Real Money Stock (M1)' m1cp = 'Lagged M1/Current GDF' y = 'Real GNP' intr = 'Yield on Corporate Bonds' infr = 'Rate of Prices Changes'; cards; 187.15 1036.22 81.18 6.84 190.63 1056.02 82.12 6.97 194.30 1068.72 82.80 6.98 198.55 1071.28 84.04 6.84 201.73 1084.15 84.97 7.32 203.18 1088.73 86.10 7.54 204.18 1091.90 87.49 7.70 206.10 1085.53 88.62 8.22 207.90 1081.32 89.89 8.86 209.78 1083.01 91.07 8.70 212.78 1093.37 91.79 9.40 216.08 1084.60 93.03 9.33 220.28 1111.55 94.40 8.74 225.25 1116.93 95.70 8.45 228.45 1125.78 96.52 8.76 230.70 1135.43 97.39 8.48 235.60 1157.21 98.72 8.23 239.38 1178.54 99.42 8.24 244.55 1193.12 100.25 8.23 250.70 1214.79 101.54 8.06 254.80 1246.72 102.95 7.90 258.40 1248.31 104.75 8.09 261.03 1255.70 106.53 8.24 264.68 1266.05 108.74 8.41 268.77 1253.34 110.72 8.58 271.23 1254.67 113.48 8.88 273.73 1246.86 116.42 9.55 276.73 1230.32 119.79 10.41 278.75 1204.26 122.88 10.62 283.80 1218.82 124.44 10.34 288.13 1246.05 126.68 10.33 290.88 1257.31 128.99 10.37 295.18 1284.97 130.12 10.24 299.53 1293.68 131.30 9.83 303.35 1301.08 132.89 9.63 309.35 1313.06 134.99 9.29 316.55 1341.23 136.80 9.08 321.80 1363.28 139.01 9.07 327.60 1385.80 141.03 8.87 334.80 1388.51 143.24 8.89 341.13 1400.01 145.12 9.17 348.70 1436.97 148.89 9.32 355.45 1448.82 152.02 9.60 361.38 1468.40 155.38 9.59 367.08 1472.57 158.60 10.13 376.10 1469.20 161.85 10.33 384.58 1486.59 165.13 10.29 388.38 1489.38 168.05 11.40 394.30 1496.40 171.94 12.42 390.00 1461.40 176.46 14.19 405.50 1464.20 180.24 12.67 416.10 1477.90 185.13 14.23 420.90 1513.50 190.01 15.03 429.30 1511.70 193.03 15.56 432.60 1522.10 197.71 16.17 437.50 1501.30 201.69 17.11 448.80 1483.50 203.98 17.10 451.30 1480.50 206.77 16.78 458.20 1477.10 208.52 16.80 475.70 1478.80 210.28 14.73 490.90 1491.00 212.86 13.94 505.20 1524.80 214.26 13.29 517.20 1550.20 215.88 13.39 523.40 1572.70 218.20 13.46 ; proc print data=money(obs=8); run; /*Example 4.5 continued page 245 */ title 'Partial Adjustment Money Demand Equation'; title2 'Quarterly Data - 1968:2 to 1983:4'; proc autoreg data=money outest=est covout; model m = m1cp y intr infr / dw=4 dwprob; run; /* Example 4.5 continued page 246 */ proc autoreg data=money; model m = m1cp y intr infr / nlag=1 method=ml maxit=50; output out=a p=p pm=pm r=r rm=rm ucl=ucl lcl=lcl uclm=uclm lclm=lclm; run; proc print data=a(obs=8); var p pm r rm ucl lcl uclm lclm; run; /* Example 4.6 Estimation of ARCH(2) Process */ /* Chapter 4 page 247 */ title 'IBM Stock Returns (daily)'; title2 '29jun1959 - 30jun1960'; data ibm; infile cards eof=last; input x @@; r = dif( log( x ) ); time = _n_-1; output; return; last: do i = 1 to 46; r = .; time + 1; output; end; return; cards; 445 448 450 447 451 453 454 454 459 440 446 443 443 440 439 435 435 436 435 435 435 433 429 428 425 427 425 422 409 407 423 422 417 421 424 414 419 429 426 425 424 425 425 424 425 421 414 410 411 406 406 413 411 410 405 409 410 405 401 401 401 414 419 425 423 411 414 420 412 415 412 412 411 412 409 407 408 415 413 413 410 405 410 412 413 411 411 409 406 407 410 408 408 409 410 409 405 406 405 407 409 407 409 425 425 428 436 442 442 433 435 433 435 429 439 437 439 438 435 433 437 437 444 441 440 441 439 439 438 437 441 442 441 437 427 423 424 428 428 431 425 423 420 426 418 416 419 418 416 419 425 421 422 422 417 420 417 418 419 419 417 419 422 423 422 421 421 419 418 421 420 413 413 408 409 415 415 420 420 424 426 423 423 425 431 436 436 440 436 443 445 439 443 445 450 461 471 467 462 456 464 463 465 464 456 460 458 453 453 449 447 453 450 459 457 453 455 453 450 456 461 463 463 461 465 473 473 475 499 485 491 496 504 504 509 511 524 525 541 531 529 530 531 527 525 519 514 509 505 513 525 519 519 522 522 ; proc gplot data=ibm; plot r*time / vref=0; symbol1 i=join v=none; run; /* Example 4.6 continued page 249 */ proc autoreg data=ibm maxit=50; model r = / noint garch=(q=2); output out=a cev=v; run; data b; set a; length type $ 8.; if r ^= . then do; type = 'ESTIMATE'; output; end; else do; type = 'FORECAST'; output; end; run; proc gplot data=b; plot v*time=type / href=254 vaxis=.00010 to .00035 by .00005; symbol1 i=join v=none; symbol2 i=join v=plus; run; quit; /* Example 5.1 CITIBASE Tape Format Data File */ /* Chapter 5 page 268 */ proc citibase infile=citidemo out=spbonds outcont=desc outselect type=week beginyr=90 endyr=1990 noprint; select wsp: fcpoil; run; title1 'Listing of Series Description Data Set'; proc print data=desc( drop=label ); run; title1 'Contents of Output Data Set'; proc contents data=spbonds; run; title1 'Listing of Output Data Set'; proc print data=spbonds; run; /*Example 5.2 CITIBASE Diskette Format Database */ /* Chapter 5 page 271 */ proc citibase dbname="base" type=qtr outcont=qtrvars outselect noprint; run; title1 'Quarterly Series Contained in the BASE Database'; proc print data=qtrvars( drop=label ); run; /* Example 5.2 continued page 272 */ proc citibase dbname="base" out=pce type=qtr beginyr=87; select gc:; /* order range specification */ /* select gc--gcdq;*/ /* alphabetic range specification */ /* select gc-gcdq; */ run; title1 'Personal Consumption Expenditures'; proc print data=pce noobs; run; /* Producing a Simple Report */ /* Chapter 6 page 78 */ data report; input compdiv $ date:date7. salary travel insure advrtise; format date date7.; label travel = 'Travel Expenses within U.S.' advrtise = 'Advertising' salary = 'Permanent Staff Salaries' insure = 'Benefits Including Insurance'; cards; A 31JAN89 95000 10500 2000 6500 B 31JAN89 668000 112000 5600 90000 C 31JAN89 105000 6800 9000 18500 A 28FEB89 91000 8200 1900 12000 B 28FEB89 602000 99000 5500 86000 C 28FEB89 96000 6000 8500 16000 ; title 'Listing of Monthly Divisional Expense Data'; proc print data=report; run; title 'Monthly Divisional Expense Report'; proc computab data=report; run; /* Defining Report Layout */ /* Chapter 6 page 280 */ title1; proc computab data=report; rows travel advrtise salary insure; run; proc computab data= report; rows travel advrtise salary insure; columns a b c; *----select column for company division, based on value of compdiv----*; a = compdiv = 'A'; b = compdiv = 'B'; c = compdiv = 'C'; run; /* Adding Computeed Rows and Columns */ /* Chapter 6 page 281 */ proc computab data= report; rows travel advrtise salary insure sum; columns a b c total; a = compdiv = 'A'; b = compdiv = 'B'; c = compdiv = 'C'; colblk: total = a + b + c; rowblk: sum = travel + advrtise + salary + insure; run; /* Enhancing the Report */ /* Chapter 6 page 282 */ title 'Year to Date Expenses'; proc computab cwidth=8 cdec=0; columns a b c / 'Division' _name_; columns total / 'All' 'Divisions' +4 f=dollar10.0; rows travel advrtise salary insure / _label_; rows insure / dul; rows sum / 'Total'; a = compdiv = 'A'; b = compdiv = 'B'; c = compdiv = 'C'; colblk: total = a + b + c; rowblk: sum = travel + advrtise + salary + insure; run; /* Example 6.1 Using Programming Statements */ /* Chapter 6 page 304 */ title1; data bookings; input reptdate date7. la atl ch ny; cards; 01JAN89 100 110 120 130 01FEB89 140 150 160 170 01MAR89 180 190 200 210 01APR89 220 230 240 250 01MAY89 260 270 280 290 01JUN89 300 310 320 330 01JUL89 340 350 360 370 01AUG89 380 390 400 410 01SEP89 420 430 440 450 01OCT89 460 470 480 490 01NOV89 500 510 520 530 01DEC89 540 550 560 570 ; /* Example 6.1 continued page 305 */ proc computab data=bookings cspace=1 cwidth=6; columns qtr1 pct1 qtr2 pct2 qtr3 pct3 qtr4 pct4; columns qtr1-qtr4 / format=6.; columns pct1-pct4 / format=6.2; rows la atl ch ny total; /* column selection */ _col_ = qtr( reptdate ) * 2 - 1; /* copy qtr column values temporarily into pct columns */ colcopy: pct1 = qtr1; pct2 = qtr2; pct3 = qtr3; pct4 = qtr4; /* calculate total row for all columns */ /* calculate percentages for all rows in pct columns only */ rowcalc: total = la + atl + ch + ny; if mod( _col_, 2 ) = 0 then do; la = la / total * 100; atl = atl / total * 100; ch = ch / total * 100; ny = ny / total * 100; total = 100; end; run; proc computab data=bookings cspace=1 cwidth=6; columns qtr1 pct1 qtr2 pct2 qtr3 pct3 qtr4 pct4; columns qtr1-qtr4 / format=6.; columns pct1-pct4 / format=6.2; rows la atl ch ny total; array pct[4] pct1-pct4; array qt[4] qtr1-qtr4; array rowlist[5] la atl ch ny total; /* column selection */ _col_ = qtr(reptdate) * 2 - 1; /* copy qtr column values temporarily into pct columns */ colcopy: do i = 1 to 4; pct[i] = qt[i]; end; /* calculate total row for all columns */ /* calculate percentages for all rows in pct columns only */ rowcalc: total = la + atl + ch + ny; if mod(_col_,2) = 0 then do i = 1 to 5; rowlist[i] = rowlist[i] / total * 100; end; run; /* Example 6.2 Enhancing a Report */ /* Chapter 6 page 306 */ data incomrep; input type :$6. date :monyy5. sales retdis tcos selling randd general admin deprec other taxes; format date monyy5.; cards; BUDGET JAN89 4600 300 2200 480 110 500 210 14 -8 510 BUDGET FEB89 4700 330 2300 500 110 500 200 14 0 480 BUDGET MAR89 4800 360 2600 500 120 600 250 15 2 520 ACTUAL JAN89 4900 505 2100 430 130 410 200 14 -8 500 ACTUAL FEB89 5100 480 2400 510 110 390 230 15 2 490 ; title 'Computab Report without Any Specifications'; proc computab data=incomrep; run; /* Example 6.2 continued page 307 */ title 'Column Selection by Month'; proc computab data=incomrep; rows sales--other; columns jana feba mara; mnth = month(date); if type = 'ACTUAL'; jana = mnth = 1; feba = mnth = 2; mara = mnth = 3; run; /* Example 6.2 continued page 308 */ proc computab data=incomrep; /* add a new column to be selected */ /* qtr1 column will be selected several times */ columns actual1-actual3 qtr1 / nozero; array collist[3] actual1-actual3; rows sales retdis netsales tcos grosspft selling randd general admin deprec operexp operinc other taxblinc taxes netincom; if type='ACTUAL'; i = month(date); if i <= 3 then qtr1 = 1; collist[i]=1; rowcalc: if sales = . then return; netsales = sales - retdis; grosspft = netsales - tcos; operexp = selling + randd + general + admin + deprec; operinc = grosspft - operexp; taxblinc = operinc + other; netincom = taxblinc - taxes; run; /* now get the report to look the way we want it */ title 'Pro Forma Income Statement'; title2 'XYZ Computer Services, Inc.'; title3 'Period to Date Actual'; title4 'Amounts in Thousands'; proc computab data=incomrep; columns actual1-actual3 qtr1 / nozero f=comma7. +3 ' '; array collist[3] actual1-actual3; columns actual1 / 'Jan'; columns actual2 / 'Feb'; columns actual3 / 'Mar'; columns qtr1 / 'Total' 'Qtr 1'; rows sales / ' ' 'Gross Sales '; rows retdis / 'Less Returns & Discounts'; rows netsales / 'Net Sales' +3 ol; rows tcos / ' ' 'Total Cost of Sales'; rows grosspft / ' ' 'Gross Profit'; rows selling / ' ' 'Operating Expenses:' ' Selling'; rows randd / ' R & D'; rows general / +3; rows admin / ' Administrative'; rows deprec / ' Depreciation' ul; rows operexp / ' ' skip; rows operinc / 'Operating Income'; rows other / 'Other Income/-Expense' ul; rows taxblinc / 'Taxable Income'; rows taxes / 'Income Taxes' ul; rows netincom / ' Net Income' dul; if type = 'ACTUAL'; i = month( date ); collist[i] = 1; colcalc: qtr1 = actual1 + actual2 + actual3; rowcalc: if sales = . then return; netsales = sales - retdis; grosspft = netsales - tcos; operexp = selling + randd + general + admin + deprec; operinc = grosspft - operexp; taxblinc = operinc + other; netincom = taxblinc - taxes; run; /* Example 6.3 Comparison of Actual and Budget */ /* Chapter 6 page 310 */ /* do a more complex report */ title 'Pro Forma Income Statement'; title2 'XYZ Computer Services, Inc.'; title3 'Budget Analysis'; title4 'Amounts in Thousands'; proc computab data=incomrep; columns cmbud cmact cmpct ytdbud ytdact ytdpct / zero=' '; columns cmbud--cmpct / mtitle='- Current Month: February -'; columns ytdbud--ytdpct / mtitle='- Year To Date -'; columns cmbud ytdbud / 'Budget' f=comma6.; columns cmact ytdact / 'Actual' f=comma6.; columns cmpct ytdpct / '% ' f=7.2; columns cmbud--ytdpct / '-'; columns ytdbud / _titles_; retain curmo 2; /* current month: February */ rows sales / ' ' 'Gross Sales'; rows retdis / 'Less Returns & Discounts'; rows netsales / 'Net Sales' +3 ol; rows tcos / ' ' 'Total Cost of Sales'; rows grosspft / ' ' 'Gross Profit' +3; rows selling / ' ' 'Operating Expenses:' ' Selling'; rows randd / ' R & D'; rows general / +3; rows admin / ' Administrative'; rows deprec / ' Depreciation' ul; rows operexp / ' '; rows operinc / 'Operating Income' ol; rows other / 'Other Income/-Expense' ul; rows taxblinc / 'Taxable Income'; rows taxes / 'Income Taxes' ul; rows netincom / ' Net Income' dul; cmbud = type = 'BUDGET' & month(date) = curmo; cmact = type = 'ACTUAL' & month(date) = curmo; ytdbud = type = 'BUDGET' & month(date) <= curmo; ytdact = type = 'ACTUAL' & month(date) <= curmo; rowcalc: if cmpct | ytdpct then return; netsales = sales - retdis; grosspft = netsales - tcos; operexp = selling + randd + general + admin + deprec; operinc = grosspft - operexp; taxblinc = operinc + other; netincom = taxblinc - taxes; colpct: if cmbud & cmact then cmpct = 100 * cmact / cmbud; if ytdbud & ytdact then ytdpct = 100 * ytdact / ytdbud; run; /* Example 6.4 Consolidations */ /* Chapter 6 page 312 */ data product; input pcode div region month sold revenue recd cost; cards; 1 1 1 1 56 5600 29 2465 1 1 1 2 13 1300 30 2550 1 1 1 3 17 1700 65 5525 2 1 1 1 2 240 50 4900 2 1 1 2 82 9840 17 1666 1 1 1 1 37 3700 75 6375 2 1 1 1 84 10080 28 2744 3 1 1 1 19 2470 73 7884 1 1 1 2 8 800 74 6290 2 1 1 2 71 8520 77 7546 3 1 1 2 49 6370 19 2052 1 1 1 3 16 1600 40 3400 2 1 1 3 46 5520 86 8428 3 1 1 3 40 5200 19 2052 1 1 2 1 17 1700 24 2040 2 1 2 1 29 3480 57 5586 3 1 2 1 36 4680 81 8748 1 1 2 2 62 6200 37 3145 2 1 2 2 21 2520 6 588 3 1 2 2 97 12610 24 2592 1 1 2 3 63 6300 3 255 2 1 2 3 84 10080 99 9702 3 1 2 3 36 4680 22 2376 4 2 1 1 42 840 14 224 5 2 1 1 75 2250 6 132 6 2 1 1 77 3080 79 2212 4 2 1 2 56 1120 16 256 5 2 1 2 32 960 64 1408 6 2 1 2 65 2600 84 2352 4 2 1 3 22 440 92 1472 5 2 1 3 3 90 87 1914 6 2 1 3 49 1960 56 1568 4 2 2 1 30 600 49 784 5 2 2 1 37 1110 47 1034 6 2 2 1 49 1960 44 1232 4 2 2 2 81 1620 85 1360 5 2 2 2 39 1170 61 1342 6 2 2 2 7 280 79 2212 4 2 2 3 95 1900 74 1184 5 2 2 3 91 2730 50 1100 6 2 2 3 65 2600 41 1148 ; proc format; value divfmt 1='Equipment' 2='Publishing'; value regfmt 1='North Central' 2='Northeast' 3='South' 4='West'; run; proc sort data=product; by div region pcode; run; title1 ' XYZ Development Corporation '; title2 ' Corporate Headquarters: New York, NY '; title3 ' Profit Summary '; title4 ' '; proc computab data=product sumonly; by div region pcode; sumby _total_ div region; format div divfmt.; format region regfmt.; label div = 'DIVISION'; /* specify order of columns and column titles */ columns jan feb mar qtr1 / mtitle='- first quarter -' ' ' nozero; columns apr may jun qtr2 / mtitle='- second quarter -' ' ' nozero; columns jul aug sep qtr3 / mtitle='- third quarter -' ' ' nozero; columns oct nov dec qtr4 / mtitle='- fourth quarter -' ' ' nozero; column jan / ' ' 'January' '='; column feb / ' ' 'February' '='; column mar / ' ' 'March' '='; column qtr1 / 'Quarter' 'Summary' '='; column apr / ' ' 'April' '=' _page_; column may / ' ' 'May' '='; column jun / ' ' 'June' '='; column qtr2 / 'Quarter' 'Summary' '='; column jul / ' ' 'July' '=' _page_; column aug / ' ' 'August' '='; column sep / ' ' 'September' '='; column qtr3 / 'Quarter' 'Summary' '='; column oct / ' ' 'October' '=' _page_; column nov / ' ' 'November' '='; column dec / ' ' 'December' '='; column qtr4 / 'Quarter' 'Summary' '='; /* specify order of rows and row titles */ row sold / ' ' 'Number Sold' f=8.; row revenue / ' ' 'Sales Revenue'; row recd / ' ' 'Number Received' f=8.; row cost / ' ' 'Cost of' 'Items Received'; row profit / ' ' 'Profit' 'Within Period' ol; row pctmarg / ' ' 'Profit Margin' dul; /* select column for appropriate month */ _col_ = month + ceil( month / 3 ) - 1; /* calculate quarterly summary columns */ colcalc: qtr1 = jan + feb + mar; qtr2 = apr + may + jun; qtr3 = jul + aug + sep; qtr4 = oct + nov + dec; /* calculate profit rows */ rowcalc: profit = revenue - cost; if cost > 0 then pctmarg = profit / cost * 100; run; /* Example 6.5 Creating an Output Data Set */ /* Chapter 6 page 315 */ data product; input pcode div region month sold revenue recd cost; cards; 1 1 1 1 56 5600 29 2465 1 1 1 2 13 1300 30 2550 1 1 1 3 17 1700 65 5525 2 1 1 1 2 240 50 4900 2 1 1 2 82 9840 17 1666 1 1 1 1 37 3700 75 6375 2 1 1 1 84 10080 28 2744 3 1 1 1 19 2470 73 7884 1 1 1 2 8 800 74 6290 2 1 1 2 71 8520 77 7546 3 1 1 2 49 6370 19 2052 1 1 1 3 16 1600 40 3400 2 1 1 3 46 5520 86 8428 3 1 1 3 40 5200 19 2052 1 1 1 4 17 1700 24 2040 2 1 1 4 29 3480 57 5586 3 1 1 4 36 4680 81 8748 1 1 1 5 62 6200 37 3145 2 1 1 5 21 2520 6 588 3 1 1 5 97 12610 24 2592 1 1 1 6 63 6300 3 255 2 1 1 6 84 10080 99 9702 3 1 1 6 36 4680 22 2376 1 1 1 7 42 4200 14 1190 2 1 1 7 75 9000 6 588 3 1 1 7 77 10010 79 8532 1 1 1 8 56 5600 16 1360 2 1 1 8 32 3840 64 6272 3 1 1 8 65 8450 84 9072 1 1 1 9 22 2200 92 7820 2 1 1 9 3 360 87 8526 3 1 1 9 49 6370 56 6048 1 1 1 10 30 3000 49 4165 2 1 1 10 37 4440 47 4606 3 1 1 10 49 6370 44 4752 1 1 1 11 81 8100 85 7225 2 1 1 11 39 4680 61 5978 3 1 1 11 7 910 79 8532 1 1 1 12 95 9500 74 6290 2 1 1 12 91 10920 50 4900 3 1 1 12 65 8450 41 4428 1 1 2 1 64 6400 60 5100 2 1 2 1 61 7320 67 6566 3 1 2 1 70 9100 65 7020 1 1 2 2 86 8600 50 4250 2 1 2 2 59 7080 51 4998 3 1 2 2 83 10790 6 648 1 1 2 3 74 7400 52 4420 2 1 2 3 27 3240 99 9702 3 1 2 3 77 10010 16 1728 1 1 2 4 22 2200 60 5100 2 1 2 4 70 8400 32 3136 3 1 2 4 5 650 91 9828 1 1 2 5 85 8500 84 7140 2 1 2 5 11 1320 38 3724 3 1 2 5 18 2340 43 4644 1 1 2 6 46 4600 84 7140 2 1 2 6 88 10560 57 5586 3 1 2 6 5 650 47 5076 1 1 2 7 30 3000 22 1870 2 1 2 7 72 8640 79 7742 3 1 2 7 59 7670 52 5616 1 1 2 8 36 3600 41 3485 2 1 2 8 94 11280 34 3332 3 1 2 8 36 4680 2 216 1 1 2 9 55 5500 72 6120 2 1 2 9 84 10080 14 1372 3 1 2 9 43 5590 99 10692 1 1 2 10 64 6400 91 7735 2 1 2 10 46 5520 64 6272 3 1 2 10 32 4160 78 8424 1 1 2 11 55 5500 95 8075 2 1 2 11 6 720 70 6860 3 1 2 11 6 780 15 1620 1 1 2 12 86 8600 50 4250 2 1 2 12 89 10680 73 7154 3 1 2 12 69 8970 35 3780 ; proc sort data=product out=sorted; by div region; run; /* create data set, profit */ proc computab data=sorted notrans out=profit noprint; by div region; sumby div; /* specify order of rows and row titles */ row jan feb mar qtr1; row apr may jun qtr2; row jul aug sep qtr3; row oct nov dec qtr4; /* specify order of columns and column titles */ columns sold revenue recd cost profit pctmarg; /* select row for appropriate month */ _row_ = month + ceil( month / 3 ) - 1; /* calculate quarterly summary rows */ rowcalc: qtr1 = jan + feb + mar; qtr2 = apr + may + jun; qtr3 = jul + aug + sep; qtr4 = oct + nov + dec; /* calculate profit columns */ colcalc: profit = revenue - cost; if cost > 0 then pctmarg = profit / cost * 100; run; /* make a partial listing of the output data set */ proc print data=profit (obs=10) noobs; run; /* Example 6.6 A What-If Market Analysis */ /* Chapter 6 page 316 */ data market; input date :yyq4. units @@; cards; 80Q1 3608.9 80Q2 5638.4 80Q3 6017.9 80Q4 4929.6 81Q1 4962.0 81Q2 5804.6 81Q3 5498.6 81Q4 7687.1 82Q1 6864.1 82Q2 7625.8 82Q3 7919.7 82Q4 8294.7 83Q1 8151.6 83Q2 10992.7 83Q3 10671.4 83Q4 10643.2 84Q1 10215.1 84Q2 10795.5 84Q3 14144.4 84Q4 11623.1 85Q1 14445.3 85Q2 13925.2 85Q3 16729.3 85Q4 16125.3 86Q1 15232.6 86Q2 16272.2 86Q3 16816.7 86Q4 17040.0 87Q1 17967.8 87Q2 14727.2 87Q3 18797.3 87Q4 18258.0 88Q1 20041.5 88Q2 20181.0 88Q3 20061.7 88Q4 21670.1 89Q1 21844.3 89Q2 23524.1 89Q3 22000.6 89Q4 24166.7 ; /* forecast the total number of units to be */ /* sold in the next four quarters */ proc forecast out=outcome trend=2 interval=qtr lead=4; id date; var units; run; /* Example 6.6 continued page 317 */ /* set up rows and columns of report and initialize */ /* market share and program constants */ %macro whatif(mktshr=,price=,ucost=,taxrate=,numshar=,overhead=); columns mar / ' ' 'March'; columns jun / ' ' 'June'; columns sep / ' ' 'September'; columns dec / ' ' 'December'; columns total / 'Calculated' 'Total'; rows mktshr / 'Market Share' f=5.2; rows tunits / 'Market Forecast'; rows units / 'Items Sold'; rows sales / 'Sales'; rows cost / 'Cost of Goods'; rows ovhd / 'Overhead'; rows gprof / 'Gross Profit'; rows tax / 'Tax'; rows pat / 'Profit After Tax'; rows earn / 'Earnings per Share'; rows mktshr--earn / skip; rows sales--earn / f=dollar12.2; rows tunits units / f=comma12.2; /* initialize market share values */ init mktshr &mktshr; /* define constants */ retain price &price ucost &ucost taxrate &taxrate numshar &numshar; /* retain overhead and sales from previous quarter */ retain prevovhd &overhead prevsale; %mend whatif; /* perform calculations and print the specified rows */ %macro show(rows); /* initialize list of row names */ %let row1 = mktshr; %let row2 = tunits; %let row3 = units; %let row4 = sales; %let row5 = cost; %let row6 = ovhd; %let row7 = gprof; %let row8 = tax; %let row9 = pat; %let row10 = earn; /* find parameter row names in list and eliminate */ /* them from the list of noprint rows */ %let n = 1; %let word = %scan(&rows,&n); %do %while(&word NE ); %let i = 1; %let row11 = &word; %do %while(&&row&i NE &word); %let i = %eval(&i+1); %end; %if &i<11 %then %let row&i = ; %let n = %eval(&n+1); %let word = %scan(&rows,&n); %end; rows &row1 &row2 &row3 &row4 &row5 &row6 &row7 &row8 &row9 &row10 dummy / noprint; /* select column using lead values from proc forecast */ mar = _lead_ = 1; jun = _lead_ = 2; sep = _lead_ = 3; dec = _lead_ = 4; rowreln:; /* inter-relationships */ share = round( mktshr, 0.01 ); tunits = units; units = share * tunits; sales = units * price; cost = units * ucost; /* calculate overhead */ if mar then prevsale = sales; if sales > prevsale then ovhd = prevovhd + .05 * ( sales - prevsale ); else ovhd = prevovhd; prevovhd = ovhd; prevsale = sales; gprof = sales - cost - ovhd; tax = gprof * taxrate; pat = gprof - tax; earn = pat / numshar; coltot:; if mktshr then total = ( mar + jun + sep + dec ) / 4; else total = mar + jun + sep + dec; %mend show; run; /* Example 6.6 continued page 319 */ title1 'Fleet Footwear, Inc.'; title2 'Marketing Analysis Income Statement'; title3 'Based on Forecasted Unit Sales'; title4 'All Values Shown'; proc computab data=outcome cwidth=12; %whatif(mktshr=.02 .07 .15 .25,price=38.00, ucost=20.00,taxrate=.48,numshar=15000,overhead=5000); %show(mktshr tunits units sales cost ovhd gprof tax pat earn); run; title3 'Revised'; title4 'Selected Values Shown'; proc computab data=outcome cwidth=12; %whatif(mktshr=.01 .06 .12 .20,price=38.00, ucost=23.00,taxrate=.48,numshar=15000,overhead=5000); %show(mktshr tunits sales pat earn); run; /* Example 6.7 Cash Flows */ /* Chapter 6 page 320 */ data cashflow; input date date7. netinc depr borrow invest tax div adv ; cards; 30MAR82 65 42 32 126 43 51 41 30JUN82 68 47 32 144 45 54 46 30SEP82 70 49 30 148 46 55 47 30DEC82 73 49 30 148 48 55 47 ; title1 'Blue Sky Endeavors'; title2 'Financial Summary'; title4 '(Dollar Figures in Thousands)'; proc computab data=cashflow; cols qtr1 qtr2 qtr3 qtr4 / 'Quarter' f=7.1; col qtr1 / 'One'; col qtr2 / 'Two'; col qtr3 / 'Three'; col qtr4 / 'Four'; row begcash / 'Beginning Cash'; row netinc / 'Income' ' Net income'; row depr / 'Depreciation'; row borrow; row subtot1 / 'Subtotal'; row invest / 'Expenditures' ' Investment'; row tax / 'Taxes'; row div / 'Dividend'; row adv / 'Advertising'; row subtot2 / 'Subtotal'; row cashflow/ skip; row irret / 'Internal Rate' 'of Return' zero=' '; rows depr borrow subtot1 tax div adv subtot2 / +3; retain cashin -5; _col_ = qtr( date ); rowblock: subtot1 = netinc + depr + borrow; subtot2 = tax + div + adv; begcash = cashin; cashflow = begcash + subtot1 - subtot2; irret = cashflow; cashin = cashflow; colblock: if begcash then cashin = qtr1; if irret then do; temp = irr( 4, cashin, qtr1, qtr2, qtr3, qtr4 ); qtr1 = temp; qtr2 = 0; qtr3 = 0; qtr4 = 0; end; run; /* Example 7.1 BEA National Income and Product Accounts */ /* Chapter 7 page 368 */ filename datafile 'host-specific-path-name' host-options; proc datasource filetype=beanipa infile=datafile interval=qtr out=foreign; keep __00100 __00800; where partno='4' and tabnum='02'; label __00100='Exports of Goods and Services'; label __00800='Imports of Goods and Services'; rename __00100=exports __00800=imports; run; goptions cback=white colors=( black ) hpos=120 vpos=50; goptions hpos=120 vpos=50; proc gplot data=foreign; title1 h=3 f=swissx 'Exports and Imports of Goods and Services'; where date > '01jan70'd; symbol1 i=spline v=I f=special h=1.5 l=1 w=1; symbol2 i=spline v=D f=special h=1.5 l=1 w=1; axis1 label=( h=2 ) value=(h=1.5); axis2 label=( a=-90 r=90 h=2 'Billions of ' h=2.5 '$$' ) value=(h=1.5); plot exports*date=1 imports*date=2 / haxis=axis1 vaxis=axis2 overlay; footnote1 j=c box=2 f=special h=2 'I I I' f=swiss h=2 ' Exports ' f=special h=2 'D D D' f=swiss h=2 ' Imports'; footnote2 j=l h=1.5 "Source: U.S. Department of Commerce, " "Bureau of Economic Analysis," h=1.5; footnote3 j=l h=1.5 " National Income and Products " "Account tape" lspace=0.5; run; symbol1; axis1; title1; footnote1; /* Example 7.2 BLS Consumer Price Index Surveys */ /* Chapter 7 page 369 */ filename datafile 'host-specific-file-name' ; proc datasource filetype=blscpi interval=month outby=cpikey outcont=cpicont; where survey='CU'; run; title1 'Partial Listing of the OUTBY= Data Set'; proc print data=cpikey noobs; where upcase(areaname) in ('NORTHEAST','NORTH CENTRAL','SOUTH','WEST'); run; title1 'Partial Listing of the OUTCONT= Data Set'; proc print data=cpicont noobs; where index( upcase(label), 'MEDICAL CARE' ); run; title1; /* Example 7.2 continued page 370 */ proc format; value $areafmt '0100' = 'Northeast Region' '0200' = 'North Central Region' '0300' = 'Southern Region' '0400' = 'Western Region'; run; filename datafile 'host-specific-file-name' ; proc datasource filetype=blscpi interval=month out=medical outall=medinfo; where survey='CU' and area in ( '0100','0200','0300','0400' ); keep a512; range from 1980:5; format area $areafmt.; rename a512=medcare; run; title1 'Information on Medical Care Service'; proc print data=medinfo; run; title1; /* Example 7.2 continued page 371 */ data medical; set medical; medcare = medcare * 0.1; run; goptions cback=white colors=( black ) hpos=120 vpos=50; goptions hpos=120 vpos=50; proc gplot data=medical; title1 h=3 f=swissx 'Consumer Price Indices for Medical Care Services'; title2 h=2 f=swissx 'Base Period: 1982-84=100'; where (date between '01may82'd and '01sep84'd) and medcare^=.; symbol1 i=spline v=J f=special h=2.5 l=1 w=1; /* area='0100' */ symbol2 i=spline v=K f=special h=2.5 l=2 w=1; /* area='0200' */ symbol3 i=spline v=L f=special h=2.5 l=3 w=1; /* area='0300' */ symbol4 i=spline v=M f=special h=2.5 l=4 w=1; /* area='0400' */ axis1 order=('01may82'd to '01sep84'd by month4) label=(h=2) v=(h=1.5); axis2 order=(88 to 112 by 2) v=(h=1.5) label=(a=-90 r=90 h=2 'Price Index'); legend1 frame label=none shape=symbol(6,2) mode=share value=(h=1.5) position=(top left inside) offset=(5,-5) across=1; plot medcare*date=area / vref=100 haxis=axis1 vaxis=axis2 legend=legend1; footnote1 j=l "Source: U.S. Dept. of Labor, Bureau of Labor " "Statistics, CPI Survey Tape" lspace=0.5; run; symbol1; axis1; legend1; title1; footnote1; /* Example 7.3 BLS State and Area, Employment, Hours and Earnings Survey */ /* Chapter 7 page 373 */ filename datafile 'host-specific-file-name' ; proc datasource filetype=blseesa out=totemp; where division='3' and industry='0000' and detail='1' and area='0000'; keep sa1; range from 1990:3 to 1990:3; rename sa1=totemp; run; libname maps 'SAS-data-library'; goptions cback=white colors=( black ) border device=xcolor hpos=80 vpos=35; libname maps '/sas/m607f3/graph/maps'; goptions border device=xcolor hpos=80 vpos=35; proc format; value totempfm low - 2000='0-2000' 2001- 4000='2001-4000' 4001-6000='4001-6000' 6001-8000='6001-8000' 8001-10000='8001-10000' 10001-12000='10001-12000' 12001-16000='12001-16000' 16001-high='over 16000'; run; proc gmap map=maps.us data=totemp; title1 h=2 f=swissx "Total Employment in Manufacturing Industries"; title2 h=2 f=swissx "as of March, 1990"; id state; /* State FIPS codes common to both US and TOTEMP data sets */ format totemp totempfm.; pattern1 v=m2n0; pattern2 v=m2n45; pattern3 v=m2n90; pattern4 v=m2n135; pattern5 v=m2x0; pattern6 v=m2x45; pattern7 v=m4x90; pattern8 v=m4x135; legend1 frame label=none shape=bar(2.4,0.6) across=4; choro totemp / discrete legend=legend1; footnote1 j=l "Source: U.S. Department of Labor, Bureau of Labor " "Statistics, Employment and Earnings Tape"; footnote2 j=l 'US map data set supplied with SAS/GRAPH' '02'x ' Software' lspace=0.5 h=0.5; run; title1; footnote1; /* Example 7.4 Tape Format CITIBASE Files */ /* Chapter 7 page 374 */ proc datasource filetype=citidemo infile=citidemo interval=weekday outall=alloff outby=keyoff outselect=off; keep dsiusnysecm dc:; run; title1 'Summary Information on Daily Data for CITIDEMO File'; proc print data=keyoff; run; title1 'Daily Series Available in CITIDEMO File'; proc print data=alloff( keep=name kept selected st_date end_date ntime nobs code ); run; /* Example 7.4 continued page 375 */ proc datasource filetype=citidemo infile=citidemo interval=weekday outall=allon outby=keyon outselect=on; keep dsiusnysecm dc:; run; title1 'Summary Information on Daily Data for CITIDEMO File'; proc print data=keyon; run; title1 'Daily Series Available in CITIDEMO File'; proc print data=allon( keep=name kept selected st_date end_date ntime nobs code ); run; /* Example 7.4 continued page 376 */ proc datasource filetype=citidemo infile=citidemo interval=weekday outby=keyrange out=citiday outselect=on; keep dsiusnysecm dc:; range to '12jan88'd; run; title1 'Summary Information on Daily Data for CITIDEMO File'; proc print data=keyrange; run; title1 'Daily Data in CITIDEMO File'; proc print data=citiday; run; /* Example 7.5 PC Diskette Format CITIBASE Database */ /* Chapter 7 page 378 */ filename keyfile 'host-specific-key-file-name' ; filename indfile 'host-specific-ind-file-name' ; filename dbfile 'host-specific-db-file-name' ; proc datasource filetype=citidisk infile=( keyfile indfile dbfile ) out=popest outall=popinfo; keep panf1-panf16 panm1-panm16; range from 1980; run; /* Example 7.6 Quarterly COMPUSTAT Data Files */ /* Chapter 7 page 379 */ filename compstat 'host-specific-Compustat-file-name' ; proc datasource filetype=cs48qibm infile=compstat out=stocks outby=company; keep data56 qftnt14; rename data56=comstock qftnt14=ftcomstk; label data56='Common Stock' qftnt14='Footnote for Common Stock'; where dnum in (7370,7371) and zlist=06 and file=06; run; /*- add company name to the out= data set */ data stocks; merge stocks company( keep=dnum cnum cic coname ); by dnum cnum cic; run; title1 'Common Stocks for Software Companies for 1990'; proc print data=stocks noobs; where date between '01jan90'd and '31dec90'd; run; /* Example 7.7 Annual COMPUSTAT Data Files */ /* Chapter 7 page 381 */ filename compfile 'host-specific-file-name' ; %macro whstmt( fileref ); %global whexpr; data _null_; infile &fileref end=last; length cnum $ 6; input dnum cnum cic; call symput( 'dnum'||left(_n_), left(dnum) ); call symput( 'cnum'||left(_n_), cnum ); call symput( 'cic' ||left(_n_), left(cic) ); if last then call symput( 'n', left(_n_) ); run; %do i = 1 %to &n; %let whexpr = &whexpr (DNUM=&&dnum&i and CNUM="&&cnum&i" and CIC=&&cic&i); %if &i ^= &n %then %let whexpr = &whexpr or; %end; %mend whstmt; %whstmt( compfile ); filename compustat 'host-specific-Compustat-file-name' ; proc datasource filetype=csaibm infile=compstat outby=company out=dataset; where &whexpr; run; /* Example 7.7 continued page 382 */ filename whexpr 'host-specific-WHEXPR-file-name' ; data _null_; infile compfile end=last; file whexpr; length cnum $ 6; input dnum cnum cic; put "( " dnum= "and CNUM='" cnum $6. "' and " cic= ")" @; if not last then put ' or'; else put ';' ; run; filename compstat 'host-specific-Compustat-file-name' ; proc datasource filetype=csaibm infile=compustat outby=company out=dataset; where %inc 'host-specific-WHEXPR-file-name'; run; title1 'Information on Selected Companies'; proc print data=company; run; /* Example 7.8 CRSP Daily NYSE/AMEX Combined Stocks */ /* Chapter 7 page 383 */ proc datasource filetype=crspdci infile=calfile out=caldata; run; proc datasource filetype=crspdca infile=( secfile1 secfile2 secfile3 ) out=annual; run; proc datasource filetype=crspdcs infile=( calfile secfile1 secfile2 secfile3 ) out=periodic index outevent=events; run; title1 'First 5 Observations in the Calendar/Indices File'; proc print data=caldata( obs=5 ); run; title1 'Last 5 Observations in the Calendar/Indices File'; proc print data=caldata( firstobs=6659 ) noobs; run; title1 "Periodic Series for CUSIP='09523220'"; title2 "DATE >= '22dec88'd"; proc print data=periodic; where cusip='09523220' and date >= '22dec88'd; run; title2; title1 "Events for CUSIP='09523220'"; proc print data=events; where cusip='09523220'; run; /* Example 7.8 continue page 386 */ proc datasource filetype=crspdcs infile=( calfile secfile1 secfile2 secfile3 ) out=both outevent=events; where cusip='09523220'; keep bidlo askhi prc vol ret sxret bxret ncusip shrout divamt; run; title1 "Printout of the First 4 Observations"; title2 "CUSIP = '09523220'"; proc print data=both noobs; var cusip date vol ncusip divamt shrout; where cusip='09523220' and date <= '08may88'd; run; title1 "Printout of the Observations centered Around 18jul88"; title2 "CUSIP = '09523220'"; proc print data=both noobs; var cusip date vol ncusip divamt shrout; where cusip='09523220' and date between '14jul88'd and '20jul88'd; run; title1 "Printout of the Observations centered Around 30sep88"; title2 "CUSIP = '09523220'"; proc print data=both noobs; var cusip date vol ncusip divamt shrout; where cusip='09523220' and date between '28sep88'd and '04oct88'd; run; /* Example 7.8 continued page 387 */ proc datasource filetype=crspdxc infile=( calfile secfile1) outevent=subevts; where cusip='09523220'; keepevent ncusip shrout; run; title1 "NCUSIP and SHROUT for CUSIP='09523220'"; proc print data=subevts noobs; run; /* Example 7.9 IMF Direction of Trade Statistics */ /* Chapter 7 page 388 */ filename dotsfile 'host-specific-gfs-file-name' ; proc datasource filetype=imfdotsp infile=dotsfile interval=qtr out=foreign outall=forngvar; where country='111' and partner='158'; run; /* Example 7.10 IMF Government Fianance Statistics */ /* Chapter 7 page 388 */ filename gfsfile 'host-specific-gfs-file-name' ; proc datasource filetype=imfgfsp infile=gfsfile outall=expvars; where country='111'; keep g8h2:; run; proc print data=expvars( where=(length(name)<=5) ); var name label st_date end_date du_name ndec; run; /* Example 7.10 continued page 389 */ proc datasource filetype=imfgfsp infile=gfsfile out=expend; where country='111'; keep g8h2 g8h2b g8h2c g8h2d g8h2e g8h2f g8h2g g8h2h g8h2n; rename g8h2=total g8h2b=defense g8h2c=educat g8h2d=health g8h2e=socsec g8h2f=housing g8h2g=recraff g8h2h=econaff g8h2n=goods; run; /* Example 8.1 Combining Monthly and Quarterly Data */ /* Chapter 8 page 414 */ data qtrly; set sashelp.citiqtr; where date >= '1jan1990'd & date < '1jan1992'd ; keep date gdp gd; run; title "Quarterly Data"; proc print data=qtrly; run; /* Example 8.1 continued page 415 */ data monthly; set sashelp.citimon; where date >= '1jan1990'd & date < '1jan1992'd ; keep date ip lhur; run; title "Monthly Data"; proc print data=monthly; run; /* Example 8.1 continued page 416 */ proc expand data=qtrly out=temp from=qtr to=month; convert gdp gd / observed=average; id date; run; data combined; merge monthly temp; by date; run; title "Combined Data Set"; proc print data=combined; run; /* Example 8.2 Interpolating Irregular Observations */ /* Chapter 8 page 417 */ data samples; input date : date. defects @@; label defects = "Defects per 1000 units"; format date date.; cards; 13jan92 55 27jan92 73 19feb92 84 8mar92 69 27mar92 66 5apr92 77 29apr92 63 11may92 81 25may92 89 7jun92 94 23jun92 105 11jul92 97 15aug92 112 29aug92 89 10sep92 77 27sep92 82 ; title "Sampled Defect Rates"; proc print data=samples; run; proc expand data=samples out=monthly to=month; id date; convert defects / observed=(beginning,average); run; title "Estimated Monthly Average Defect Rates"; proc print data=monthly; run; /* Example 8.2 continued page 418 */ proc expand data=samples out=daily to=day; id date; convert defects = interpol; run; data daily; merge daily samples; by date; run; title "Plot of Interpolated Defect Rate Curve"; proc gplot data=daily; symbol1 i=none v=star h=2; symbol2 i=join v=none; plot defects * date = 1 interpol * date = 2 / overlay; run; /* Example 8.3 Using Transformations */ /* Chapter 8 page 419 */ data test; input year qtr x; date = yyq( year, qtr ); format date yyqc.; cards; 1989 3 5238 1989 4 5289 1990 1 5375 1990 2 5443 1990 3 5514 1990 4 5527 1991 1 5557 1991 2 5615 ; proc expand data=test out=out method=none; id date; convert x = x_lag2 / transform=(lag 2); convert x = x_lag1 / transform=(lag 1); convert x; convert x = x_lead1 / transform=(lead 1); convert x = x_lead2 / transform=(lead 2); convert x = x_movave / transform=(movave 3); run; title "Transformed Series"; proc print data=out; run; /* Getting Started */ /* Chapter 9 page 424 */ title1; data past; keep date sales; format date monyy5.; lu = 0; n = 25; do i = -10 to n; u = .7 * lu + .2 * rannor(1234); lu = u; sales = 10 + .10 * i + u; date = intnx( 'month', '1jul91'd, i - n ); if i > 0 then output; end; run; proc print data=past; run; proc forecast data=past lead=10 out=pred; var sales; run; proc print data=pred; run; /* Chapter 9 page 425 */ proc forecast data=past interval=month lead=10 out=pred outlimit; var sales; id date; run; proc print data=pred; run; /* Plotting Forecasts */ /* Chapter 9 page 427 */ proc forecast data=past interval=month lead=10 out=pred outfull; id date; var sales; run; proc gplot data=pred; plot sales * date = _type_ / haxis= '1jan90'd to '1jan93'd by qtr href='15jul91'd; symbol1 i=none v=star h=2; /* for _type_=ACTUAL */ symbol2 i=spline v=circle; /* for _type_=FORECAST */ symbol3 i=spline l=3; /* for _type_=L95 */ symbol4 i=spline l=3; /* for _type_=U95 */ where date >= '1jan90'd; run; /* Plotting Residuals */ /* Chapter 9 page 428 */ proc forecast data=past interval=month lead=10 out=pred outfull outresid; id date; var sales; run; proc gplot data=pred; where _type_='RESIDUAL'; plot sales * date / haxis= '1jan89'd to '1oct91'd by qtr; symbol1 i=needle; run; /* Model Parameters and Goodness-of-Fit Statistics */ /* Chapter 9 page 429 */ proc forecast data=past interval=month lead=10 out=pred outfull outresid outest=est outfitstats; id date; var sales; run; proc print data=est; run; /* Controlling the Forecasting Method */ /* Chapter 9 page 430 */ proc forecast data=past interval=month lead=10 method=expo trend=2 out=pred outfull outresid outest=est outfitstats; var sales; id date; run; proc print data=est; run; /* Example 9.1 Forecasting Auto Sales */ /* Chapter 9 page 460 */ title1 "Sales of Passenger Cars"; symbol1 i=spline v=plus; proc gplot data=sashelp.usecon; plot vehicles * date = 1 / haxis= '1jan80'd to '1jan92'd by year; where date >= '1jan80'd; format date year4.; run; proc forecast data=sashelp.usecon interval=month method=winters seasons=month lead=12 out=out outfull outresid outest=est; id date; var vehicles; where date >= '1jan80'd; run; /* Example 9.1 continued page 459 */ title2 'The OUT= Data Set'; proc print data=out; run; title2 'The OUTEST= Data Set: WINTERS Method'; proc print data=est; run; /* Example 9.1 continued page 460 */ title2 'Plot of Residuals'; symbol1 i=needle; proc gplot data=out; plot vehicles * date = 1 / vref=0 haxis= '1jan80'd to '1jan92'd by year; where _type_ = 'RESIDUAL'; format date year4.; run; /* Example 9.1 continued page 461 */ title2 'Plot of Forecast from WINTERS Method'; symbol1 i=none v=star h=2; /* for _type_=ACTUAL */ symbol2 i=spline v=plus h=2; /* for _type_=FORECAST */ symbol3 i=spline l=3; /* for _type_=L95 */ symbol4 i=spline l=3; /* for _type_=U95 */ proc gplot data=out; plot vehicles * date = _type_ / href= '15dec91'd haxis= '1jan90'd to '1jan93'd by qtr; where _type_ ^= 'RESIDUAL' & date >= '1jan90'd; run; /* Example 9.2 Forecasting Retail Sales */ /* Chapter 9 page 462 */ title1; symbol1 i=spline v=plus; proc gplot data=sashelp.usecon; plot ( durables nondur ) * date = 1 / haxis= '1jan80'd to '1jan92'd by year; where date >= '1jan80'd; format date year4.; run; /* Example 9.2 continued page 464 */ title1 "Forecasting Sales of Durable and Nondurable Goods"; proc forecast data=sashelp.usecon interval=month method=stepar trend=2 lead=12 out=out outfull outest=est; id date; var durables nondur; where date >= '1jan80'd; run; title2 'OUTEST= Data Set: STEPAR Method'; proc print data=est; run; /* Example 9.2 continued page 465 */ title1 'Plot of Forecasts from STEPAR Method'; symbol1 i=none v=star h=2; /* for _type_=ACTUAL */ symbol2 i=spline v=plus h=2; /* for _type_=FORECAST */ symbol3 i=spline l=3; /* for _type_=L95 */ symbol4 i=spline l=3; /* for _type_=U95 */ proc gplot data=out; plot ( durables nondur ) * date = _type_ / href= '15dec91'd haxis= '1jan90'd to '1jan93'd by qtr; where date >= '1jan90'd; run; /* Example 9.3 Forecasting Petroleum Sales */ /* Chapter 9 page 466 */ title1 "Sales of Petroleum and Related Products"; symbol1 i=spline v=plus; proc gplot data=sashelp.usecon; plot petrol * date = 1 / haxis= '1jan80'd to '1jan92'd by year; where date >= '1jan80'd; format date year4.; run; /* Example 9.3 continued page 467 */ proc forecast data=sashelp.usecon interval=month method=expo trend=2 lead=12 out=out outfull outest=est; id date; var petrol; where date >= '1jan80'd; run; title2 'OUTEST= Data Set: EXPO Method'; proc print data=est; run; title2 'Plot of Forecast: EXPO Method'; symbol1 i=none v=star h=2; /* for _type_=ACTUAL */ symbol2 i=spline v=plus h=2; /* for _type_=FORECAST */ symbol3 i=spline l=3; /* for _type_=L95 */ symbol4 i=spline l=3; /* for _type_=U95 */ proc gplot data=out; plot petrol * date = _type_ / href= '15dec91'd haxis= '1jan89'd to '1jan93'd by qtr; where date >= '1jan89'd; run; /* Example 10.1 Discount Points for Lower Interest Rates */ /* Chapter 10 page 500 */ title1; proc loan start=1992:1 nosummaryprint amount=100000 life=360; fixed rate=8.25 label='8.25% - no discount points'; fixed rate=8 points=1000 label='8% - 1 discount point'; compare at=(48 54 60) all taxrate=33 marr=4; run; /* Example 10.2 Refinancing a Loan */ /* Chapter 10 page 501 */ proc loan start=1990:6; fixed life=180 rate=10 amount=78500 noprint label='Original loan'; compare at=('10FEB92'd) ; run; /* Example 10.2 continued page 502 */ proc loan start=1992:2 amount=74396.51; fixed rate=10 payment=843.57 label='Keep the original loan' noprint; fixed life=180 rate=7.5 init=1419 label='Refinance at 7.5%' noprint; compare at=(14 15) taxrate=33 marr=4 all; run; /* Example 10.3 Prepayments on a Loan */ /* Chapter 10 page 502 */ proc loan start=1992:12 rate=8.25 amount=240000 life=360; fixed label='No prepayments'; fixed label='With Prepayments' prepay=500 ; compare at=(120) taxrate=33 marr=4 all; run; /* Example 10.4 Output Data Sets */ /* Chapter 10 page 504 */ proc loan start=1992:12 noprint outsum=loans amount=100000 life=360; fixed rate=13 life=180 prepayment=200 label='BANK1, Fixed Rate'; arm rate=10.5 estimatedcase=(12=11.5 18=12) label='BANK1, Adjustable Rate'; buydown rate=12 interval=semimonth init=15000 bdrates=(3=14 10=16) label='BANK2, Buydown'; arm rate=10.8 worstcase caps=(0.5, 2.5) adjustfreq=6 label='BANK3, Adjustable Rate' prepayments=(12=2000 36=5000); balloon rate=13 life=480 points=1100 balloonpayment=(15=2000 48=1000) label='BANK4, with Balloon Payment'; compare at=(120 360) all marr=12 tax=33 outcomp=comp; run; proc print data=loans; run; proc print data=comp; run; /* Monte Carlo Simulation */ /* Chapter 11 page 522 */ data exchange ; input yr rate_jp rate_wg imn_jp imn_wg emp_us emp_jp emp_wg prod_us / prod_jp prod_wg cpi_us cpi_jp cpi_wg; im_jp = imn_jp/cpi_us; im_wg = imn_wg/cpi_us; ius = 100*(cpi_us-(lag(cpi_us)))/(lag(cpi_us)); ijp = 100*(cpi_jp-(lag(cpi_jp)))/(lag(cpi_jp)); iwg = 100*(cpi_wg-(lag(cpi_wg)))/(lag(cpi_wg)); di_jp = ius - ijp; di_wg = ius - iwg; title 'EXCHANGE Data'; cards; 1974 . . . . . . . . . . .493 .590 .672 1975 295.78 2.4613 11425 5410 93.0 99.8 103.3 93.5 84.0 89.3 .538 .660 .712 1976 296.45 2.5184 15504 5592 96.4 100.8 100.8 97.1 95.6 94.9 .569 .721 .742 1977 268.62 2.3236 18550 7238 100.0 100.0 100.0 100.0 100.0 100.0 .606 .780 .769 1978 210.38 2.0096 24458 9962 104.2 98.9 99.4 100.9 106.8 103.8 .652 .813 .790 1979 219.02 1.8342 26248 10955 107.1 98.1 99.8 101.5 117.4 108.9 .726 .843 .823 1980 226.63 1.8175 30714 11693 103.3 101.3 100.4 101.7 125.4 109.8 .824 .909 .868 1981 220.63 2.2631 37612 11379 102.8 102.2 97.9 104.6 126.3 112.8 .909 .954 .922 1982 249.06 2.4280 37744 11975 95.8 101.4 95.0 107.1 146.8 113.3 .965 .980 .970 1983 237.55 2.5539 41183 12695 94.4 103.4 91.1 111.6 152.8 116.8 .996 .999 1.003 1984 237.45 2.8454 57135 16996 99.0 105.8 90.4 118.5 152.2 124.7 1.039 1.021 1.027 1985 238.47 2.9419 68783 20239 98.1 107.6 91.3 124.2 161.1 128.5 1.076 1.042 1.048 1986 168.35 2.1704 81911 25124 96.8 107.3 92.7 128.8 163.8 130.7 1.096 1.049 1.047 1987 144.60 1.7981 84575 27069 97.1 106.1 92.8 132.0 176.5 129.9 1.136 1.050 1.049 1988 128.17 1.7569 89802 26503 99.6 108.8 92.7 136.2 190.0 135.9 1.183 1.057 1.063 ; /* data for simulation */ data whatif; input yr rate_jp rate_wg imn_jp imn_wg emp_us emp_jp emp_wg prod_us / prod_jp prod_wg cpi_us cpi_jp cpi_wg; label cpi_us = 'US CPI 1982-1984 = 100' cpi_jp = 'JP CPI 1982-1984 = 100' cpi_wg = 'WG CPI 1982-1984 = 100'; im_jp = imn_jp/cpi_us; im_wg = imn_wg/cpi_us; ius = 100*(cpi_us-(lag(cpi_us)))/(lag(cpi_us)); ijp = 100*(cpi_jp-(lag(cpi_jp)))/(lag(cpi_jp)); iwg = 100*(cpi_wg-(lag(cpi_wg)))/(lag(cpi_wg)); di_jp = ius - ijp; di_wg = ius - iwg; cards; 1980 226.63 1.8175 30714 11693 103.3 101.3 100.4 101.7 125.4 109.8 .824 .909 .868 1981 220.63 2.2631 35000 11000 102.8 102.2 97.9 104.6 126.3 112.8 .909 .954 .922 1982 249.06 2.4280 40000 12000 95.8 101.4 95.0 107.1 146.8 113.3 .965 .980 .970 1983 237.55 2.5539 45000 13100 94.4 103.4 91.1 111.6 152.8 116.8 .996 .999 1.003 1984 237.45 2.8454 50000 14300 99.0 105.8 90.4 118.5 152.2 124.7 1.039 1.021 1.027 1985 238.47 2.9419 55000 15600 98.1 107.6 91.3 124.2 161.1 128.5 1.076 1.042 1.048 1986 . . 60000 17000 96.8 107.3 92.7 128.8 163.8 130.7 1.096 1.049 1.047 1987 . . 65000 18500 97.1 106.1 92.8 132.0 176.5 129.9 1.136 1.050 1.049 1988 . . 70000 20000 99.6 108.8 92.7 136.2 190.0 135.9 1.183 1.057 1.063 ; proc model data=exchange outmodel=xch_out; parms a1 a2 b1 b2 c1 c2; label rate_jp = 'Exchange Rate of Yen/$' rate_wg = 'Exchange Rate of Gm/$' im_jp = 'Imports to US from Japan in 1984 $' im_wg = 'Imports to US from WG in 1984 $' di_jp = 'Difference in Inflation Rates US-JP' di_wg = 'Difference in Inflation Rates US-WG'; rate_jp = a1 + b1*im_jp + c1*di_jp; rate_wg = a2 + b2*im_wg + c2*di_wg; endo im_jp im_wg; exo di_jp di_wg; fit rate_jp rate_wg / sur outest=xch_est outcov outs=s; solve rate_jp rate_wg / data=whatif estdata=xch_est sdata=s random=100 seed=123 out=monte forecast; id yr; range yr=1986; run; proc sort data=monte; by yr; run; proc univariate data=monte noprint; by yr; var rate_jp rate_wg; output out=bounds mean=mean p5=p5 p95=p95; run; title "Monte Carlo Generated Confidence Intervals on a Forecast"; proc gplot data=bounds; plot mean*yr p5*yr p95*yr /overlay; symbol1 i=join value=triangle; symbol2 i=join value=square l=4; symbol3 i=join value=square l=4; run; /* Example 11.1 OLS Single Nonlinear Equation */ /* Chapter 11 page 657 */ title 'Logistic Growth Curve Model of U.S. Population'; data uspop; input pop :6.3 @@; retain year 1780; year=year+10; label pop='U.S. Population in Millions'; cards; 3929 5308 7239 9638 12866 17069 23191 31443 39818 50155 62947 75994 91972 105710 122775 131669 151325 179323 203211 226542 248710 ; proc model data=uspop; label a = 'Maximum Population' b = 'Location Parameter' c = 'Initial Growth Rate'; pop = a / ( 1 + exp( b - c * (year-1790) ) ); fit pop start=(a 1000 b 5.5 c .02)/ out=resid outresid; run; /* Example 11.1 continued page 658 */ proc gplot data=resid; plot pop*year / vref=0 haxis=1780 to 2000 by 20; title "Residual"; symbol1 v=plus; run; /* Example 11.2 A Consumer Demand Model */ /* Chapter 11 page 659 */ /* Read in price and share data */ data tlog1; input t share1 share2 share3 p1 p2 p3; cards; 1 0.129 0.493 0.378 1.40406 1.49089 1.39449 2 0.126 0.499 0.375 1.43488 1.52051 1.52407 3 0.114 0.522 0.364 1.57969 1.46667 1.65631 4 0.119 0.511 0.370 1.49961 1.55867 1.92536 5 0.126 0.509 0.365 2.01051 1.61371 1.78626 6 0.127 0.497 0.376 1.65436 1.69078 1.70540 7 0.128 0.495 0.377 1.62652 1.66765 1.61266 8 0.119 0.514 0.367 1.66980 1.50343 1.47088 9 0.125 0.499 0.376 1.40209 1.48202 1.45782 10 0.108 0.523 0.369 1.38906 1.42591 1.51648 11 0.106 0.538 0.356 1.43997 1.34984 1.46885 12 0.102 0.544 0.354 1.33201 1.31234 1.42404 13 0.102 0.540 0.358 1.17398 1.27947 1.33307 14 0.136 0.471 0.393 1.12215 1.29747 1.22201 15 0.164 0.535 0.301 1.18175 1.27395 1.13321 16 0.111 0.532 0.357 1.08195 1.24290 1.10386 17 0.125 0.503 0.372 1.02606 1.17886 1.04558 18 0.127 0.497 0.376 1.01399 1.12550 0.95515 19 0.145 0.458 0.397 1.31784 1.11050 0.89666 20 0.164 0.492 0.314 1.13912 1.10141 0.89219 21 0.130 0.492 0.378 0.94897 1.06430 0.92483 22 0.139 0.472 0.389 1.03611 0.99587 0.88390 23 0.134 0.483 0.383 0.95167 0.97834 0.84329 24 0.138 0.475 0.387 0.94553 0.91948 0.82540 25 0.130 0.486 0.384 0.82124 0.88765 0.84305 26 0.142 0.467 0.391 0.91700 0.83821 0.81825 27 0.140 0.471 0.389 0.81815 0.80076 0.80307 28 0.139 0.473 0.388 0.75771 0.76853 0.78136 29 0.136 0.481 0.383 0.66028 0.76027 0.77448 30 0.129 0.483 0.388 0.72626 0.72469 0.74480 31 0.138 0.476 0.386 0.65864 0.69642 0.73169 32 0.141 0.470 0.389 0.70983 0.66085 0.70354 33 0.140 0.471 0.389 0.67501 0.64329 0.68928 34 0.140 0.472 0.388 0.64815 0.62016 0.67150 35 0.149 0.443 0.408 0.62117 0.60156 0.65453 36 0.140 0.472 0.388 0.61053 0.56857 0.62066 37 0.140 0.471 0.389 0.61021 0.53726 0.58696 38 0.140 0.472 0.388 0.57732 0.51423 0.55821 39 0.139 0.474 0.387 0.52595 0.49851 0.54516 40 0.138 0.476 0.386 0.48673 0.48049 0.52500 41 0.159 0.483 0.358 0.51146 0.45405 0.49703 42 0.137 0.478 0.385 0.43755 0.45166 0.49636 43 0.137 0.478 0.385 0.41167 0.43600 0.49146 44 0.138 0.475 0.387 0.43348 0.40635 0.46186 ; title1 'Consumer Demand--Translog Functional Form'; title2 'Nonsymmetric Model'; proc model data=tlog1; var share1 share2 p1 p2 p3; parms a1 a2 b11 b12 b13 b21 b22 b23 b31 b32 b33; bm1 = b11 + b21 + b31; bm2 = b12 + b22 + b32; bm3 = b13 + b23 + b33; lp1 = log(p1); lp2 = log(p2); lp3 = log(p3); share1 = ( a1 + b11 * lp1 + b12 * lp2 + b13 * lp3 ) / ( -1 + bm1 * lp1 + bm2 * lp2 + bm3 * lp3 ); share2 = ( a2 + b21 * lp1 + b22 * lp2 + b23 * lp3 ) / ( -1 + bm1 * lp1 + bm2 * lp2 + bm3 * lp3 ); fit share1 share2 start=( a1 -.14 a2 -.45 b11 .03 b12 .47 b22 .98 b31 .20 b32 1.11 b33 .71 ) / outsused = smatrix sur; run; /* Example 11.2 continued page 661 */ title2 'Symmetric Model'; proc model data=tlog1; var share1 share2 p1 p2 p3; parms a1 a2 b11 b12 b22 b31 b32 b33; bm1 = b11 + b12 + b31; bm2 = b12 + b22 + b32; bm3 = b31 + b32 + b33; lp1 = log(p1); lp2 = log(p2); lp3 = log(p3); share1 = ( a1 + b11 * lp1 + b12 * lp2 + b31 * lp3 ) / ( -1 + bm1 * lp1 + bm2 * lp2 + bm3 * lp3 ); share2 = ( a2 + b12 * lp1 + b22 * lp2 + b32 * lp3 ) / ( -1 + bm1 * lp1 + bm2 * lp2 + bm3 * lp3 ); fit share1 share2 start=( a1 -.14 a2 -.45 b11 .03 b12 .47 b22 .98 b31 .20 b32 1.11 b33 .71 ) / sdata=smatrix sur; run; data _null_; /* {it reduced-full}, {it nrestrictions} */ p = 1-probchi( 1.4399, 3 ); put p=; run; /* Example 11.2 continued page 661 */ title2 'Symmetric Model'; proc model data=tlog1; var share1 share2 p1 p2 p3; parms a1 a2 b11 b12 b22 b31 b32 b33; bm1 = b11 + b12 + b31; bm2 = b12 + b22 + b32; bm3 = b31 + b32 + b33; lp1 = log(p1); lp2 = log(p2); lp3 = log(p3); share1 = ( a1 + b11 * lp1 + b12 * lp2 + b31 * lp3 ) / ( -1 + bm1 * lp1 + bm2 * lp2 + bm3 * lp3 ); share2 = ( a2 + b12 * lp1 + b22 * lp2 + b32 * lp3 ) / ( -1 + bm1 * lp1 + bm2 * lp2 + bm3 * lp3 ); fit share1 share2 start=( a1 -.14 a2 -.45 b11 .03 b12 .47 b22 .98 b31 .20 b32 1.11 b33 .71 ) / sdata=smatrix sur; run; data _null_; /* {it reduced-full}, {it nrestrictions} */ p = 1-probchi( 1.4399, 3 ); put p=; run; /* Example 11.3 Vector AR(1) Estimation */ /* Chapter 11 page 663 */ data grunfeld; input year gei gef gec whi whf whc; label gei = 'Gross Investment GE' gec = 'Capital Stock Lagged GE' gef = 'Value of Outstanding Shares GE Lagged' whi = 'Gross Investment WH' whc = 'Capital Stock Lagged WH' whf = 'Value of Outstanding Shares Lagged WH'; cards; 1935 33.1 1170.6 97.8 12.93 191.5 1.8 1936 45.0 2015.8 104.4 25.90 516.0 .8 1937 77.2 2803.3 118.0 35.05 729.0 7.4 1938 44.6 2039.7 156.2 22.89 560.4 18.1 1939 48.1 2256.2 172.6 18.84 519.9 23.5 1940 74.4 2132.2 186.6 28.57 628.5 26.5 1941 113.0 1834.1 220.9 48.51 537.1 36.2 1942 91.9 1588.0 287.8 43.34 561.2 60.8 1943 61.3 1749.4 319.9 37.02 617.2 84.4 1944 56.8 1687.2 321.3 37.81 626.7 91.2 1945 93.6 2007.7 319.6 39.27 737.2 92.4 1946 159.9 2208.3 346.0 53.46 760.5 86.0 1947 147.2 1656.7 456.4 55.56 581.4 111.1 1948 146.3 1604.4 543.4 49.56 662.3 130.6 1949 98.3 1431.8 618.3 32.04 583.8 141.8 1950 93.5 1610.5 647.4 32.24 635.2 136.7 1951 135.2 1819.4 671.3 54.38 723.8 129.7 1952 157.3 2079.7 726.1 71.78 864.1 145.5 1953 179.5 2371.6 800.3 90.08 1193.5 174.8 1954 189.6 2759.9 888.9 68.60 1188.9 213.5 ; title1 'Example of Vector AR(1) Error Process Using Grunfeld''s Model'; /* Note: GE stands for General Electric and WH for Westinghouse */ proc model outmodel=grunmod; var gei whi gef gec whf whc; parms ge_int ge_f ge_c wh_int wh_f wh_c; label ge_int = 'GE Intercept' ge_f = 'GE Lagged Share Value Coef' ge_c = 'GE Lagged Capital Stock Coef' wh_int = 'WH Intercept' wh_f = 'WH Lagged Share Value Coef' wh_c = 'WH Lagged Capital Stock Coef'; gei = ge_int + ge_f * gef + ge_c * gec; whi = wh_int + wh_f * whf + wh_c * whc; run; /* Example 11.3 continued page 664 */ title2 'With Unrestricted Vector AR(1) Error Process'; proc model data=grunfeld model=grunmod; %ar( ar, 1, gei whi ) fit gei whi / sur; run; title2 'With restricted AR(1) Error Process'; proc model data=grunfeld model=grunmod; %ar( gei, 1 ) %ar( whi, 1) fit gei whi / sur; run; /* Example 11.4 MA(1) Estimation */ /* Chapter 11 page 666 */ title1 'Example of MA(1) Error Process Using Grunfeld''s Model'; title2 'MA(1) Error Process Using Unconditional Least Squares'; proc model data=grunfeld model=grunmod; %ma(gei,1, m=uls); %ma(whi,1, m=uls); fit whi gei start=( gei_m1 0.8 -0.8) / startiter=2; run; /* Example 11.4 continued page 667 */ title2 'PROC ARIMA Using Unconditional Least Squares'; proc arima data=grunfeld; identify var=whi cross=(whf whc ) noprint; estimate q=1 input=(whf whc) method=uls maxiter=40; run; title2 'MA(1) Error Process Using Maximum Likelihood '; proc model data=grunfeld model=grunmod; %ma(gei,1, m=ml); %ma(whi,1, m=ml); fit whi gei; run; title2 'PROC ARIMA Using Maximum Likelihood '; proc arima data=grunfeld; identify var=whi cross=(whf whc) noprint; estimate q=1 input=(whf whc) method=ml; run; /* Example 11.5 Polynomial Distributed Lags Using %PDL */ /* Chapter 11 page 669 */ /*--------------------------------------------------------------*/ /* Generate Simulated Data for a Linear Model with a PDL on X */ /* y = 10 + x(6,2) + e */ /* pdl(x) = -5.*(lg)**2 + 1.5*(lg) + 0. */ /*--------------------------------------------------------------*/ data pdl; pdl2=-5.; pdl1=1.5; pdl0=0; array zz(i) z0-z6; do i=1 to 7; z=i-1; zz=pdl2*z**2 + pdl1*z + pdl0; end; do n=-11 to 30; x =10*ranuni(1234567)-5; pdl=z0*x + z1*xl1 + z2*xl2 + z3*xl3 + z4*xl4 + z5*xl5 + z6*xl6; e =10*rannor(123); y =10+pdl+e; if n>=1 then output; xl6=xl5; xl5=xl4; xl4=xl3; xl3=xl2; xl2=xl1; xl1=x; end; run; title1 'Polynomial Distributed Lag Example'; title3 'Estimation of PDL(6,4) Model-- No Endpoint Restrictions'; proc model data=pdl; parms int; /* declare the intercept parameter */ %pdl( xpdl, 6, 4 ) /* declare the lag distribution */ y = int + %pdl( xpdl, x ); /* define the model equation */ fit y / list; /* estimate the parameters */ run; /* Example 11.5 continued page 670 */ title3 'Estimation of PDL(6,4) Model-- Both Endpoint Restrictions'; proc model data=pdl ; parms int; /* declare the intercept parameter */ %pdl( xpdl, 6, 4, r=both ) /* declare the lag distribution */ y = int + %pdl( xpdl, x ); /* define the model equation */ fit y /list; /* estimate the parameters */ run; /* Example 11.5 continued page 671 */ title3 'Estimation of PDL(6,2) Model-- With XPDL_0 Dropped'; proc model data=pdl list; parms int; /* declare the intercept parameter */ %pdl( xpdl, 6, 2 ) /* declare the lag distribution */ y = int + %pdl( xpdl, x ); /* define the model equation */ xpdl_0 =0; fit y drop=xpdl_0; /* estimate the parameters */ run; /* Example 11.6 General-Form Equations */ /* Chapter 11 page 672 */ data history; input year income unitcost price quantity; cards; 1976 2221.87 3.31220 0.17903 266.714 1977 2254.77 3.61647 0.06757 276.049 1978 2285.16 2.21601 0.82916 285.858 1979 2319.37 3.28257 0.33202 295.034 1980 2369.38 2.84494 0.63564 310.773 1981 2395.26 2.94154 0.62011 319.185 1982 2419.52 2.65301 0.80753 325.970 1983 2475.09 2.41686 1.01017 342.470 1984 2495.09 3.44096 0.52025 348.321 1985 2536.72 2.30601 1.15053 360.750 ; data assume; input year income unitcost; cards; 1986 2571.87 2.31220 1987 2609.12 2.45633 1988 2639.77 2.51647 1989 2667.77 1.65617 1990 2705.16 1.01601 ; data goal; input year income quantity; cards; 1986 2571.87 371.4 1987 2721.08 416.5 1988 3327.05 597.3 1989 3885.85 764.1 1990 3650.98 694.3 ; title1 "General Form Equations for Supply-Demand Model"; proc model; var price quantity income unitcost; parms d0-d2 s0-s2; eq.demand=d0+d1*price+d2*income-quantity; eq.supply=s0+s1*price+s2*unitcost-quantity; /* estimate the model parameters */ fit supply demand / data=history outest=est n2sls; instruments income unitcost year; run; /* produce forecasts for income and unitcost assumptions */ solve price quantity / data=assume out=pq; run; /* produce goal-seeking solutions for income and quantity assumptions*/ solve price unitcost / data=goal out=pc; run; title2 "Parameter Estimates for the System"; proc print data=est; run; title2 "Price Quantity Solution"; proc print data=pq; run; title2 "Price Unitcost Solution"; proc print data=pc; run; /* Example 11.7 Spring and Damper Continuous System */ /* Chapter 11 page 675 */ title1 'Simulation of Spring-Mass-Damper System'; /*- Generate some obs. to drive the simulation time periods ---*/ data one; do n=1 to 100; output; end; run; proc model data=one; var force -200 disp 10 vel 0 accel -20 time 0; control mass 9.2 c 1.5 dt .1 k 20; force = -k * disp -c * vel; disp = lag(disp) + vel * dt; vel = lag(vel) + accel * dt; accel = force / mass; time = lag(time) + dt; /*- Simulate the model for the base case -------------------*/ control run '1'; solve / out=a; run; /*- Simulate the model with half the time step -------------*/ control run '2' dt .05; solve / out=b; run; /*- Simulate the model with twice the initial displacement -*/ control run '3'; var disp 20; solve / out=c; run; /*- Plot the results ------------------------------------------*/ data p; set a b c; run; title2 'Overlay Plot of All Three Simulations'; proc gplot data=p; plot disp*time=run; run; /* Example 11.8 Nonlinear FIML Estimation */ /* Chapter 11 page 679 */ title1; data bodkin; input z1 z2 z3 z4 z5; cards; 1.33135 0.64629 0.4026 -20 0.24447 1.39235 0.66302 0.4084 -19 0.23454 1.41640 0.65272 0.4223 -18 0.23206 1.48773 0.67318 0.4389 -17 0.22291 1.51015 0.67720 0.4605 -16 0.22487 1.43385 0.65175 0.4445 -15 0.21879 1.48188 0.65570 0.4387 -14 0.23203 1.67115 0.71417 0.4999 -13 0.23828 1.71327 0.77524 0.5264 -12 0.26571 1.76412 0.79465 0.5793 -11 0.23410 1.76869 0.71607 0.5492 -10 0.22181 1.80776 0.70068 0.5052 -9 0.18157 1.54947 0.60764 0.4679 -8 0.22931 1.66933 0.67041 0.5283 -7 0.20595 1.93377 0.74091 0.5994 -6 0.19472 1.95460 0.71336 0.5964 -5 0.17981 2.11198 0.75159 0.6554 -4 0.18010 2.26266 0.78838 0.6851 -3 0.16933 2.33228 0.79600 0.6933 -2 0.16279 2.43980 0.80788 0.7061 -1 0.16906 2.58714 0.84547 0.7567 0 0.16239 2.54865 0.77232 0.6796 1 0.16103 2.26042 0.67880 0.6136 2 0.14456 1.91974 0.58529 0.5145 3 0.20079 1.80000 0.58065 0.5046 4 0.18307 1.86020 0.62007 0.5711 5 0.18352 1.88201 0.65575 0.6184 6 0.18847 1.97018 0.72433 0.7113 7 0.20415 2.08232 0.76838 0.7461 8 0.18847 1.94062 0.69806 0.6981 9 0.17800 1.98646 0.74679 0.7722 10 0.19979 2.07987 0.79083 0.8557 11 0.21115 2.28232 0.88462 0.9925 12 0.23453 2.52779 0.95750 1.0877 13 0.20937 2.62747 1.00285 1.1834 14 0.19843 2.61235 0.99329 1.2565 15 0.18898 2.52320 0.94857 1.2293 16 0.17203 2.44632 0.97853 1.1889 17 0.18140 2.56478 1.02591 1.2249 18 0.19431 2.64588 1.03760 1.2669 19 0.19492 2.69105 0.99669 1.2708 20 0.17912 ; proc model data=bodkin; parms c1-c5; endogenous z1 z2; exogenous z3 z4 z5; eq.g1 = c1 * 10 **(c2 * z4) * (c5*z1**(-c4)+ (1-c5)*z2**(-c4))**(-c3/c4) - z3; eq.g2 = (c5/(1-c5))*(z1/z2)**(-1-c4) -z5; fit g1 g2 / fiml ; run; /* Example 12.1 Calculating Monthly Payment for a Mortgage */ /* Chapter 12 page 693 */ title 'Calculating the payment for a fixed-rate mortgage'; proc mortgage amount=74600 rate=.0875 life=180 nyears=3 out=schedule firstpayment=1984:9; run; title2 'Partial Listing of PROC MORTGAGE OUT= Data Set'; proc print data=schedule(obs=6); run; /* Example 12.2 Quarterly versus Continuous Compounding */ /* Chapter 12 page 695 */ proc mortgage nyears=0 amount=100000 rate=.15 life=20 interval=quarter; run; proc mortgage nyears=0 amount=100000 rate=.1475 life=20 interval=quarter compound=continuous; run; /* Introductory PDLREG Example */ /* Chapter 13 page 701 */ title1; data test; xl1 = 0; xl2 = 0; xl3 = 0; do t = -3 to 100; x = ranuni(1234); y = 10 + .25 * xl1 + .5 * xl2 + .25 * xl3 + .1 * rannor(1234); if t > 0 then output; xl3 = xl2; xl2 = xl1; xl1 = x; end; run; proc pdlreg data=test; model y = x( 4, 3 ); run; /* Example 13.1 Industrial Conference Board Data */ /* Chapter 13 page 713 */ title 'National Industrial Conference Board Data'; title2 'Quarterly Series - 1952Q1 to 1967Q4'; data a; input ce ca @@; qtr = mod( _n_-1, 4 ) + 1; q1 = qtr=1; q2 = qtr=2; q3 = qtr=3; cards; 2072 1660 2077 1926 2078 2181 2043 1897 2062 1695 2067 1705 1964 1731 1981 2151 1914 2556 1991 3152 2129 3763 2309 3903 2614 3912 2896 3571 3058 3199 3309 3262 3446 3476 3466 2993 3435 2262 3183 2011 2697 1511 2338 1631 2140 1990 2012 1993 2071 2520 2192 2804 2240 2919 2421 3024 2639 2725 2733 2321 2721 2131 2640 2552 2513 2234 2448 2282 2429 2533 2516 2517 2534 2772 2494 2380 2596 2568 2572 2944 2601 2629 2648 3133 2840 3449 2937 3764 3136 3983 3299 4381 3514 4786 3815 4094 4093 4870 4262 5344 4531 5433 4825 5911 5160 6109 5319 6542 5574 5785 5749 5707 5715 5412 5637 5465 5383 5550 5467 5465 ; proc pdlreg data=a; model ce = q1 q2 q3 ca(5,2) / dwprob; run; /* Example 13.1 continued page 715 */ data b; set a; ca_1 = lag( ca ); ca_2 = lag2( ca ); ca_3 = lag3( ca ); ca_4 = lag4( ca ); ca_5 = lag5( ca ); run; proc reg data=b; model ce = q1 q2 q3 ca ca_1 ca_2 ca_3 ca_4 ca_5; restrict - ca + 5*ca_1 - 10*ca_2 + 10*ca_3 - 5*ca_4 + ca_5; restrict ca - 3*ca_1 + 2*ca_2 + 2*ca_3 - 3*ca_4 + ca_5; restrict -5*ca + 7*ca_1 + 4*ca_2 - 4*ca_3 - 7*ca_4 + 5*ca_5; run; /* Example 13.2 Money Demand Model */ /* Chapter 13 page 716 */ title1; data a; input m1 gnp gdf r @@; m = log( 100 * m1 / gdf ); lagm = lag( m ); y = log( gnp ); p = log( gdf / lag( gdf ) ); date = intnx( 'qtr', '1jan1968'd, _n_-1 ); format date yyqc6.; label m = 'Real Money Stock (M1)' lagm = 'Lagged Real Money Stock' y = 'Real GNP' r = 'Commercial Paper Rate' p = 'Inflation Rate'; cards; 187.15 1036.22 81.18 5.58 190.63 1056.02 82.12 6.08 194.30 1068.72 82.80 5.96 198.55 1071.28 84.04 5.96 201.73 1084.15 84.97 6.66 203.18 1088.73 86.10 7.54 204.18 1091.90 87.49 8.49 206.10 1085.53 88.62 8.62 207.90 1081.32 89.89 8.55 209.78 1083.01 91.07 8.17 212.78 1093.37 91.79 7.84 216.08 1084.60 93.03 6.29 220.28 1111.55 94.40 4.59 225.25 1116.93 95.70 5.04 228.45 1125.78 96.52 5.74 230.70 1135.43 97.39 5.07 235.60 1157.21 98.72 4.06 239.38 1178.54 99.42 4.58 244.55 1193.12 100.25 4.94 250.70 1214.79 101.54 5.33 254.80 1246.72 102.95 6.28 258.40 1248.31 104.75 7.47 261.03 1255.70 106.53 9.87 264.68 1266.05 108.74 8.98 268.77 1253.34 110.72 8.30 271.23 1254.67 113.48 10.46 273.73 1246.86 116.42 11.53 276.73 1230.32 119.79 9.05 278.75 1204.26 122.88 6.56 283.80 1218.82 124.44 5.92 288.13 1246.05 126.68 6.67 290.88 1257.31 128.99 6.12 295.18 1284.97 130.12 5.29 299.53 1293.68 131.30 5.57 303.35 1301.08 132.89 5.53 309.35 1313.06 134.99 4.99 316.55 1341.23 136.80 4.81 321.80 1363.28 139.01 5.24 327.60 1385.80 141.03 5.81 334.80 1388.51 143.24 6.59 341.13 1400.01 145.12 6.80 348.70 1436.97 148.89 7.20 355.45 1448.82 152.02 8.08 361.38 1468.40 155.38 9.90 367.08 1472.57 158.60 10.10 376.10 1469.20 161.85 10.03 384.58 1486.59 165.13 10.60 388.38 1489.38 168.05 13.10 394.30 1496.40 171.94 14.25 390.00 1461.40 176.46 10.62 405.50 1464.20 180.24 9.65 416.10 1477.90 185.13 14.51 420.90 1513.50 190.01 14.52 429.30 1511.70 193.03 15.35 432.60 1522.10 197.71 16.27 437.50 1501.30 201.69 12.94 448.80 1483.50 203.98 13.70 451.30 1480.50 206.77 13.48 458.20 1477.10 208.52 11.53 475.70 1478.80 210.28 8.81 490.90 1491.00 212.86 8.34 505.20 1524.80 214.26 8.61 517.20 1550.20 215.88 9.44 523.40 1572.70 218.20 9.19 ; proc print data=a(obs=5); var date m lagm y r p; run; /* Example 13.2 continued page 717 */ title 'Money Demand Estimation using Distributed Lag Model'; title2 'Quarterly Data - 1968Q2 to 1983Q4'; proc pdlreg data=a; model m = lagm y(5,3) r(2,,,first) p(3,2) / lagdep=lagm; run; /* Example 14.1 Simulating Klein's Model 1 */ /* Chapter 14 page 736 */ data klein; input year c p w i x wp g t k wsum; date=mdy(1,1,year); format date year.; y =c+i+g-t; yr =year-1931; klag=lag(k); plag=lag(p); xlag=lag(x); if year>=1921; label c ='consumption' p ='profits' w ='private wage bill' i ='investment' k ='capital stock' y ='national income' x ='private production' wsum='total wage bill' wp ='govt wage bill' g ='govt demand' t ='taxes' klag='capital stock lagged' plag='profits lagged' xlag='private product lagged' yr ='year-1931'; cards; 1920 . 12.7 . . 44.9 . . . 182.8 . 1921 41.9 12.4 25.5 -0.2 45.6 2.7 3.9 7.7 182.6 28.2 1922 45.0 16.9 29.3 1.9 50.1 2.9 3.2 3.9 184.5 32.2 1923 49.2 18.4 34.1 5.2 57.2 2.9 2.8 4.7 189.7 37.0 1924 50.6 19.4 33.9 3.0 57.1 3.1 3.5 3.8 192.7 37.0 1925 52.6 20.1 35.4 5.1 61.0 3.2 3.3 5.5 197.8 38.6 1926 55.1 19.6 37.4 5.6 64.0 3.3 3.3 7.0 203.4 40.7 1927 56.2 19.8 37.9 4.2 64.4 3.6 4.0 6.7 207.6 41.5 1928 57.3 21.1 39.2 3.0 64.5 3.7 4.2 4.2 210.6 42.9 1929 57.8 21.7 41.3 5.1 67.0 4.0 4.1 4.0 215.7 45.3 1930 55.0 15.6 37.9 1.0 61.2 4.2 5.2 7.7 216.7 42.1 1931 50.9 11.4 34.5 -3.4 53.4 4.8 5.9 7.5 213.3 39.3 1932 45.6 7.0 29.0 -6.2 44.3 5.3 4.9 8.3 207.1 34.3 1933 46.5 11.2 28.5 -5.1 45.1 5.6 3.7 5.4 202.0 34.1 1934 48.7 12.3 30.6 -3.0 49.7 6.0 4.0 6.8 199.0 36.6 1935 51.3 14.0 33.2 -1.3 54.4 6.1 4.4 7.2 197.7 39.3 1936 57.7 17.6 36.8 2.1 62.7 7.4 2.9 8.3 199.8 44.2 1937 58.7 17.3 41.0 2.0 65.0 6.7 4.3 6.7 201.8 47.7 1938 57.5 15.3 38.2 -1.9 60.9 7.7 5.3 7.4 199.9 45.9 1939 61.6 19.0 41.6 1.3 69.5 7.8 6.6 8.9 201.2 49.4 1940 65.0 21.1 45.0 3.3 75.7 8.0 7.4 9.6 204.5 53.0 1941 69.7 23.5 53.3 4.9 88.4 8.5 13.8 11.6 209.4 61.8 1942 . . . . . 8.5 13.8 11.6 . . 1943 . . . . . 8.5 13.8 12.6 . . 1944 . . . . . 8.5 13.8 11.6 . . 1945 . . . . . 8.5 13.8 11.6 . . 1946 . . . . . 8.5 13.8 11.6 . . 1947 . . . . . 8.5 13.8 11.6 . . ; title1 'Simulation of Klein''s Model I using SIMLIN'; proc syslin 3sls data=klein outest=a; instruments klag plag xlag wp g t yr; endogenous c p w i x wsum k y; consume: model c = p plag wsum; invest: model i = p plag klag; labor: model w = x xlag yr; product: identity x = c + i + g; income: identity y = c + i + g - t; profit: identity p = x - w - t; stock: identity k = klag + i; wage: identity wsum = w + wp; run; proc print data=a; run; /* Example 14.1 continued page 738 */ title1 'Simulation of Klein''s Model I using SIMLIN'; proc simlin est=a data=klein type=3sls estprint total interim=2 outest=b; endogenous c p w i x wsum k y; exogenous wp g t yr; lagged klag k 1 plag p 1 xlag x 1; id year; output out=c p=chat phat what ihat xhat wsumhat khat yhat r=cres pres wres ires xres wsumres kres yres; run; /* Example 14.1 continued page 742 */ proc print data=b; where _type_ = 'REDUCED' | _type_ = 'IMULT1'; run; /* Example 14.1 continued page 743 */ title1 h=1 'Simulation of Klein''s Model I using SIMLIN'; title2 h=1 'Plots of Simulation Results'; symbol1 i=none v=star; symbol2 i=join v=plus h=2; proc gplot data=c; plot c*year=1 chat*year=2 / overlay href=1941.5; run; /* Example 14.2 Multipliers for a Third-Order System */ /* Chapter 14 page 744 */ data test; input y ylag1 ylag2 ylag3 x; n+1; cards; 8.2369 8.5191 6.9491 7.8800 -1.2593 8.6285 8.2369 8.5191 6.9491 -1.6805 10.2223 8.6285 8.2369 8.5191 -1.9844 10.1372 10.2223 8.6285 8.2369 -1.7855 10.0360 10.1372 10.2223 8.6285 -1.8092 10.3560 10.0360 10.1372 10.2223 -1.3921 11.4835 10.3560 10.0360 10.1372 -2.0987 10.8508 11.4835 10.3560 10.0360 -1.8788 11.2684 10.8508 11.4835 10.3560 -1.7154 12.6310 11.2684 10.8508 11.4835 -1.8418 11.9096 12.6310 11.2684 10.8508 -2.0470 12.2193 11.9096 12.6310 11.2684 -1.8109 13.0518 12.2193 11.9096 12.6310 -1.8780 12.8666 13.0518 12.2193 11.9096 -2.0845 13.3405 12.8666 13.0518 12.2193 -2.0509 13.3683 13.3405 12.8666 13.0518 -1.7805 13.1531 13.3683 13.3405 12.8666 -2.0595 14.5805 13.1531 13.3683 13.3405 -2.3643 13.1989 14.5805 13.1531 13.3683 -1.4725 12.4139 13.1989 14.5805 13.1531 -1.1796 14.8030 12.4139 13.1989 14.5805 -1.9951 13.9480 14.8030 12.4139 13.1989 -1.8967 14.3449 13.9480 14.8030 12.4139 -2.4828 16.7221 14.3449 13.9480 14.8030 -2.9054 15.9229 16.7221 14.3449 13.9480 -2.6875 16.3114 15.9229 16.7221 14.3449 -2.9113 16.7162 16.3114 15.9229 16.7221 -1.9644 15.4270 16.7162 16.3114 15.9229 -1.7433 17.1469 15.4270 16.7162 16.3114 -2.5479 16.2746 17.1469 15.4270 16.7162 -1.7809 ; title1 'Simulate Equation with Third-Order Lags'; title2 'Listing of Simulated Input Data'; proc print data=test(obs=10); run; title1 'Simulate Equation with Third-Order Lags'; title2 'Estimated Parameters'; proc reg data=test outest=a; model y=ylag3 x; run; title2 'Listing of OUTEST= Data Set'; proc print data=a; run; /* Example 14.2 continued page 745 */ title1 h=1 'Simulate Equation with Third-Order Lags'; title2 'Simulation of Equation'; proc simlin est=a data=test nored; endogenous y; exogenous x; lagged ylag3 y 3; id n; output out=out1 predicted=yhat residual=yresid; run; title1 h=1 'Simulate Equation with Third-Order Lags'; title2 'Plots of Simulation Results'; symbol1 i=none v=star; symbol2 i=join v=plus h=2; proc gplot data=out1; plot yhat*n=1 y*n=2 / overlay; run; /* Example 14.2 continued page 746 */ title1 h=1 'Simulate Equation with Third-Order Lags'; data test2; set test; ylag1x=ylag1; ylag2x=ylag2; run; title2 'Estimation of parameters and definition of identities'; proc syslin data=test2 outest=b; endogenous y ylag1x ylag2x; model y=ylag3 x; identity ylag1x=ylag1; identity ylag2x=ylag2; run; title2 'Listing of OUTEST= data set from PROC SYSLIN'; proc print data=b; run; /* Example 14.2 page 747 */ title1 h=1 'Simulate Equation with Third-Order Lags'; title2 'Simulation of transformed first-order equation system'; proc simlin est=b data=test2 total interim=2; endogenous y ylag1x ylag2x; exogenous x; lagged ylag1 y 1 ylag2 ylag1x 1 ylag3 ylag2x 1; id n; output out=out2 predicted=yhat residual=yresid; run; /* Example 15.1 Spectral Analysis of Sunspot Activity */ /* Chapter 15 page 760 */ title "Wolfer's Sunspot Data"; data sunspot; input year wolfer @@; cards; 1749 809 1750 834 1751 477 1752 478 1753 307 1754 122 1755 96 1756 102 1757 324 1758 476 1759 540 1760 629 1761 859 1762 612 1763 451 1764 364 1765 209 1766 114 1767 378 1768 698 1769 1061 1770 1008 1771 816 1772 665 1773 348 1774 306 1775 70 1776 198 1777 925 1778 1544 1779 1259 1780 848 1781 681 1782 385 1783 228 1784 102 1785 241 1786 829 1787 1320 1788 1309 1789 1181 1790 899 1791 666 1792 600 1793 469 1794 410 1795 213 1796 160 1797 64 1798 41 1799 68 1800 145 1801 340 1802 450 1803 431 1804 475 1805 422 1806 281 1807 101 1808 81 1809 25 1810 0 1811 14 1812 50 1813 122 1814 139 1815 354 1816 458 1817 411 1818 304 1819 239 1820 157 1821 66 1822 40 1823 18 1824 85 1825 166 1826 363 1827 497 1828 625 1829 670 1830 710 1831 478 1832 275 1833 85 1834 132 1835 569 1836 1215 1837 1383 1838 1032 1839 858 1840 632 1841 368 1842 242 1843 107 1844 150 1845 401 1846 615 1847 985 1848 1243 1849 959 1850 665 1851 645 1852 542 1853 390 1854 206 1855 67 1856 43 1857 228 1858 548 1859 938 1860 957 1861 772 1862 591 1863 440 1864 470 1865 305 1866 163 1867 73 1868 373 1869 739 1870 1391 1871 1112 1872 1017 1873 663 1874 447 1875 171 1876 113 1877 123 1878 34 1879 60 1880 323 1881 543 1882 597 1883 637 1884 635 1885 522 1886 254 1887 131 1888 68 1889 63 1890 71 1891 356 1892 730 1893 849 1894 780 1895 640 1896 418 1897 262 1898 267 1899 121 1900 95 1901 27 1902 50 1903 244 1904 420 1905 635 1906 538 1907 620 1908 485 1909 439 1910 186 1911 57 1912 36 1913 14 1914 96 1915 474 1916 571 1917 1039 1918 806 1919 636 1920 376 1921 261 1922 142 1923 58 1924 167 ; symbol1 i=splines v=plus; proc gplot data=sunspot; plot wolfer*year; run; /* Example 15.1 continued page 761 */ title "Wolfer's Sunspot Data"; proc spectra data=sunspot out=b p s adjmean whitetest; var wolfer; weights 1 2 3 4 3 2 1; run; proc print data=b(obs=12); run; /* Example 15.1 continued page 762 */ title "Wolfer's Sunspot Data"; symbol1 i=splines v=plus; proc gplot data=b; plot p_01 * freq; plot p_01 * period; plot s_01 * freq; plot s_01 * period; run; /* Example 15.1 continued page 765 */ title "Wolfer's Sunspot Data"; symbol1 i=splines v=plus; proc gplot data=b; where period < 50; plot s_01 * period / href=11; run; /* Example 15.2 Cross Spectral Analysis */ /* Chapter 15 page 766 */ title1; data a; xl = 0; xll = 0; do i = - 10 to 100; x = .4 * xl + rannor(123); y = .5 * xll + rannor(123); if i > 0 then output; xll = xl; xl = x; end; run; proc spectra data=a out=b cross coef a k p ph s; var x y; weights 1 1.5 2 4 8 9 8 4 2 1.5 1; run; proc contents data=b position; run; /* Example 15.2 continued page 767 */ symbol1 i=splines v=plus; proc gplot data=b; plot a_01_02 * freq; run; proc gplot data=b; plot a_01_02 * period; where period < 25; run; /* Automatic State Space Model Selection */ /* Chapter 16 page 776 */ title1; data in; x=10; y=40; x1=0; y1=0; a1=0; b1=0; iseed=123; do t=-100 to 200; a=rannor(iseed); b=rannor(iseed); dx = 0.5*x1 + 0.3*y1 + a - 0.2*a1 - 0.1*b1; dy = 0.3*x1 + 0.5*y1 + b; x = x + dx + .25; y = y + dy + .25; if t >= 0 then output; x1 = dx; y1 = dy; a1 = a; b1 = b; end; keep t x y; run; proc gplot data=in; plot ( x y ) * t = 1 / overlay; symbol1 v=plus i=join; run; proc statespace data=in out=out lead=10; var x(1) y(1); id t; run; proc print data=out; id t; where t > 190; run; /* Forecast Data Set */ /* Chapter 16 page 782 */ proc gplot data=out; plot for1*t=1 for2*t=1 x*t=2 y*t=2 / overlay href=200.5; symbol1 v=plus i=join; symbol2 v=star i=none; where t > 150; run; /* Restricting the F and G matrices */ /* Chapter 16 page 783 */ proc statespace data=in out=out lead=10; var x(1) y(1); id t; form x 2 y 1; restrict f(2,3)=0; run; /* Example 16.1 Series J from Box and Jenkins */ /* Chapter 16 page 809 */ title1 'Gas Furnace Data'; title2 'Box & Jenkins Series J'; data seriesj; input x y @@; label X='Input Gas Rate' Y='Output CO2'; cards; -0.109 53.8 0.000 53.6 0.178 53.5 0.339 53.5 0.373 53.4 0.441 53.1 0.461 52.7 0.348 52.4 0.127 52.2 -0.180 52.0 -0.588 52.0 -1.055 52.4 -1.421 53.0 -1.520 54.0 -1.302 54.9 -0.814 56.0 -0.475 56.8 -0.193 56.8 0.088 56.4 0.435 55.7 0.771 55.0 0.866 54.3 0.875 53.2 0.891 52.3 0.987 51.6 1.263 51.2 1.775 50.8 1.976 50.5 1.934 50.0 1.866 49.2 1.832 48.4 1.767 47.9 1.608 47.6 1.265 47.5 0.790 47.5 0.360 47.6 0.115 48.1 0.088 49.0 0.331 50.0 0.645 51.1 0.960 51.8 1.409 51.9 2.670 51.7 2.834 51.2 2.812 50.0 2.483 48.3 1.929 47.0 1.485 45.8 1.214 45.6 1.239 46.0 1.608 46.9 1.905 47.8 2.023 48.2 1.815 48.3 0.535 47.9 0.122 47.2 0.009 47.2 0.164 48.1 0.671 49.4 1.019 50.6 1.146 51.5 1.155 51.6 1.112 51.2 1.121 50.5 1.223 50.1 1.257 49.8 1.157 49.6 0.913 49.4 0.620 49.3 0.255 49.2 -0.280 49.3 -1.080 49.7 -1.551 50.3 -1.799 51.3 -1.825 52.8 -1.456 54.4 -0.944 56.0 -0.570 56.9 -0.431 57.5 -0.577 57.3 -0.960 56.6 -1.616 56.0 -1.875 55.4 -1.891 55.4 -1.746 56.4 -1.474 57.2 -1.201 58.0 -0.927 58.4 -0.524 58.4 0.040 58.1 0.788 57.7 0.943 57.0 0.930 56.0 1.006 54.7 1.137 53.2 1.198 52.1 1.054 51.6 0.595 51.0 -0.080 50.5 -0.314 50.4 -0.288 51.0 -0.153 51.8 -0.109 52.4 -0.187 53.0 -0.255 53.4 -0.229 53.6 -0.007 53.7 0.254 53.8 0.330 53.8 0.102 53.8 -0.423 53.3 -1.139 53.0 -2.275 52.9 -2.594 53.4 -2.716 54.6 -2.510 56.4 -1.790 58.0 -1.346 59.4 -1.081 60.2 -0.910 60.0 -0.876 59.4 -0.885 58.4 -0.800 57.6 -0.544 56.9 -0.416 56.4 -0.271 56.0 0.000 55.7 0.403 55.3 0.841 55.0 1.285 54.4 1.607 53.7 1.746 52.8 1.683 51.6 1.485 50.6 0.993 49.4 0.648 48.8 0.577 48.5 0.577 48.7 0.632 49.2 0.747 49.8 0.900 50.4 0.993 50.7 0.968 50.9 0.790 50.7 0.399 50.5 -0.161 50.4 -0.553 50.2 -0.603 50.4 -0.424 51.2 -0.194 52.3 -0.049 53.2 0.060 53.9 0.161 54.1 0.301 54.0 0.517 53.6 0.566 53.2 0.560 53.0 0.573 52.8 0.592 52.3 0.671 51.9 0.933 51.6 1.337 51.6 1.460 51.4 1.353 51.2 0.772 50.7 0.218 50.0 -0.237 49.4 -0.714 49.3 -1.099 49.7 -1.269 50.6 -1.175 51.8 -0.676 53.0 0.033 54.0 0.556 55.3 0.643 55.9 0.484 55.9 0.109 54.6 -0.310 53.5 -0.697 52.4 -1.047 52.1 -1.218 52.3 -1.183 53.0 -0.873 53.8 -0.336 54.6 0.063 55.4 0.084 55.9 0.000 55.9 0.001 55.2 0.209 54.4 0.556 53.7 0.782 53.6 0.858 53.6 0.918 53.2 0.862 52.5 0.416 52.0 -0.336 51.4 -0.959 51.0 -1.813 50.9 -2.378 52.4 -2.499 53.5 -2.473 55.6 -2.330 58.0 -2.053 59.5 -1.739 60.0 -1.261 60.4 -0.569 60.5 -0.137 60.2 -0.024 59.7 -0.050 59.0 -0.135 57.6 -0.276 56.4 -0.534 55.2 -0.871 54.5 -1.243 54.1 -1.439 54.1 -1.422 54.4 -1.175 55.5 -0.813 56.2 -0.634 57.0 -0.582 57.3 -0.625 57.4 -0.713 57.0 -0.848 56.4 -1.039 55.9 -1.346 55.5 -1.628 55.3 -1.619 55.2 -1.149 55.4 -0.488 56.0 -0.160 56.5 -0.007 57.1 -0.092 57.3 -0.620 56.8 -1.086 55.6 -1.525 55.0 -1.858 54.1 -2.029 54.3 -2.024 55.3 -1.961 56.4 -1.952 57.2 -1.794 57.8 -1.302 58.3 -1.030 58.6 -0.918 58.8 -0.798 58.8 -0.867 58.6 -1.047 58.0 -1.123 57.4 -0.876 57.0 -0.395 56.4 0.185 56.3 0.662 56.4 0.709 56.4 0.605 56.0 0.501 55.2 0.603 54.0 0.943 53.0 1.223 52.0 1.249 51.6 0.824 51.6 0.102 51.1 0.025 50.4 0.382 50.0 0.922 50.0 1.032 52.0 0.866 54.0 0.527 55.1 0.093 54.5 -0.458 52.8 -0.748 51.4 -0.947 50.8 -1.029 51.2 -0.928 52.0 -0.645 52.8 -0.424 53.8 -0.276 54.5 -0.158 54.9 -0.033 54.9 0.102 54.8 0.251 54.4 0.280 53.7 0.000 53.3 -0.493 52.8 -0.759 52.6 -0.824 52.6 -0.740 53.0 -0.528 54.3 -0.204 56.0 0.034 57.0 0.204 58.0 0.253 58.6 0.195 58.5 0.131 58.3 0.017 57.8 -0.182 57.3 -0.262 57.0 ; title3 'Automatically Selected Model'; proc statespace data=seriesj cancorr; var x y; run; /* Example 16.1 continued page 812 */ title1 'Gas Furnace Data'; title2 'Box & Jenkins Series J'; title3 'Transfer Function Model'; proc statespace data=seriesj printout=none; var x y; restrict f(3,2)=0 f(3,4)=0 g(3,2)=0 g(4,1)=0 g(5,1)=0; run; title1 'Gas Furnace Data'; title2 'Box & Jenkins Series J'; /* more complicated transfer function model */ title3 'More Complex Transfer Function Model'; proc statespace data=seriesj printout=none; var x y; form x 3 y 3; restrict f(5,2)=0 f(5,4)=0 f(5,6)=0 g(3,2)=0 g(4,1)=0 g(5,2)=0 g(6,1)=0; run; /* Example 17.1 Klein's Model I */ /* Chapter 17 page 856 */ title1; *---------------------------Klein's Model I----------------------------* | By L.R. Klein, Economic Fluctuations in the United States, 1921-1941 | | (1950), NY: John Wiley. A macro-economic model of the U.S. with | | three behavioral equations, and several identities. See Theil, p.456.| *----------------------------------------------------------------------*; data klein; input year c p w i x wp g t k wsum; date=mdy(1,1,year); format date monyy.; y =c+i+g-t; yr =year-1931; klag=lag(k); plag=lag(p); xlag=lag(x); label year='Year' date='Date' c ='Consumption' p ='Profits' w ='Private Wage Bill' i ='Investment' k ='Capital Stock' y ='National Income' x ='Private Production' wsum='Total Wage Bill' wp ='Govt Wage Bill' g ='Govt Demand' i ='Taxes' klag='Capital Stock Lagged' plag='Profits Lagged' xlag='Private Product Lagged' yr ='YEAR-1931'; cards; 1920 . 12.7 . . 44.9 . . . 182.8 . 1921 41.9 12.4 25.5 -0.2 45.6 2.7 3.9 7.7 182.6 28.2 1922 45.0 16.9 29.3 1.9 50.1 2.9 3.2 3.9 184.5 32.2 1923 49.2 18.4 34.1 5.2 57.2 2.9 2.8 4.7 189.7 37.0 1924 50.6 19.4 33.9 3.0 57.1 3.1 3.5 3.8 192.7 37.0 1925 52.6 20.1 35.4 5.1 61.0 3.2 3.3 5.5 197.8 38.6 1926 55.1 19.6 37.4 5.6 64.0 3.3 3.3 7.0 203.4 40.7 1927 56.2 19.8 37.9 4.2 64.4 3.6 4.0 6.7 207.6 41.5 1928 57.3 21.1 39.2 3.0 64.5 3.7 4.2 4.2 210.6 42.9 1929 57.8 21.7 41.3 5.1 67.0 4.0 4.1 4.0 215.7 45.3 1930 55.0 15.6 37.9 1.0 61.2 4.2 5.2 7.7 216.7 42.1 1931 50.9 11.4 34.5 -3.4 53.4 4.8 5.9 7.5 213.3 39.3 1932 45.6 7.0 29.0 -6.2 44.3 5.3 4.9 8.3 207.1 34.3 1933 46.5 11.2 28.5 -5.1 45.1 5.6 3.7 5.4 202.0 34.1 1934 48.7 12.3 30.6 -3.0 49.7 6.0 4.0 6.8 199.0 36.6 1935 51.3 14.0 33.2 -1.3 54.4 6.1 4.4 7.2 197.7 39.3 1936 57.7 17.6 36.8 2.1 62.7 7.4 2.9 8.3 199.8 44.2 1937 58.7 17.3 41.0 2.0 65.0 6.7 4.3 6.7 201.8 47.7 1938 57.5 15.3 38.2 -1.9 60.9 7.7 5.3 7.4 199.9 45.9 1939 61.6 19.0 41.6 1.3 69.5 7.8 6.6 8.9 201.2 49.4 1940 65.0 21.1 45.0 3.3 75.7 8.0 7.4 9.6 204.5 53.0 1941 69.7 23.5 53.3 4.9 88.4 8.5 13.8 11.6 209.4 61.8 ; proc syslin data=klein outest=b liml; endogenous c p w i x wsum k y; instruments klag plag xlag wp g t yr; consume: model c = p plag wsum; invest: model i = p plag klag; labor: model w = x xlag yr; run; proc print data=b; run; /* Example 17.1 continued page 859 */ proc syslin data=klein 3sls reduced; endogenous c p w i x wsum k y; instruments klag plag xlag wp g t yr; consume: model c = p plag wsum; invest: model i = p plag klag; labor: model w = x xlag yr; product: identity x = c + i + g; income: identity y = c + i + g - t; profit: identity p = y - w - wp; stock: identity k = klag + i; wage: identity wsum = w + wp; run; /* Example 17.2 Grunfeld's Model */ /* Chapter 17 page 863 */ *-------------Zellners'S Seemingly Unrelated Technique------------------* | A. Zellner, "An Efficient Method of Estimating Seemingly Unrelated | | Regressions and Tests for Aggregation Bias," JASA 57(1962) pp.348-364 | | J.C.G. Boot, "Investment Demand: an Empirical Contribution to the | | Aggregation Problem," IER 1(1960) pp.3-30. | | Y. Grunfeld, "The Determinants of Corporate Investment," Unpublished | | thesis, Chicago, 1958 | *-----------------------------------------------------------------------*; data grunfeld; input year ge_i ge_f ge_c wh_i wh_f wh_c; label ge_i = 'Gross Investment, GE' ge_c = 'Capital Stock Lagged, GE' ge_f = 'Value of Outstanding Shares Lagged, GE' wh_i = 'Gross Investment, WH' wh_c = 'Capital Stock Lagged, WH' wh_f = 'Value of Outstanding Shares Lagged, WH'; cards; 1935 33.1 1170.6 97.8 12.93 191.5 1.8 1936 45.0 2015.8 104.4 25.90 516.0 .8 1937 77.2 2803.3 118.0 35.05 729.0 7.4 1938 44.6 2039.7 156.2 22.89 560.4 18.1 1939 48.1 2256.2 172.6 18.84 519.9 23.5 1940 74.4 2132.2 186.6 28.57 628.5 26.5 1941 113.0 1834.1 220.9 48.51 537.1 36.2 1942 91.9 1588.0 287.8 43.34 561.2 60.8 1943 61.3 1749.4 319.9 37.02 617.2 84.4 1944 56.8 1687.2 321.3 37.81 626.7 91.2 1945 93.6 2007.7 319.6 39.27 737.2 92.4 1946 159.9 2208.3 346.0 53.46 760.5 86.0 1947 147.2 1656.7 456.4 55.56 581.4 111.1 1948 146.3 1604.4 543.4 49.56 662.3 130.6 1949 98.3 1431.8 618.3 32.04 583.8 141.8 1950 93.5 1610.5 647.4 32.24 635.2 136.7 1951 135.2 1819.4 671.3 54.38 723.8 129.7 1952 157.3 2079.7 726.1 71.78 864.1 145.5 1953 179.5 2371.6 800.3 90.08 1193.5 174.8 1954 189.6 2759.9 888.9 68.60 1188.9 213.5 ; proc syslin data=grunfeld sur; ge: model ge_i = ge_f ge_c; westing: model wh_i = wh_f wh_c; run; /* Introductory Example */ /* Chapter 18 page 873 */ title1; data greene; input firm year output cost @@; df1 = firm = 1; df2 = firm = 2; df3 = firm = 3; df4 = firm = 4; df5 = firm = 5; d60 = year = 1960; d65 = year = 1965; d70 = year = 1970; cards; 1 1955 5.36598 1.14867 1 1960 6.03787 1.45185 1 1965 6.37673 1.52257 1 1970 6.93245 1.76627 2 1955 6.54535 1.35041 2 1960 6.69827 1.71109 2 1965 7.40245 2.09519 2 1970 7.82644 2.39480 3 1955 8.07153 2.94628 3 1960 8.47679 3.25967 3 1965 8.66923 3.47952 3 1970 9.13508 3.71795 4 1955 8.64259 3.56187 4 1960 8.93748 3.93400 4 1965 9.23073 4.11161 4 1970 9.52530 4.35523 5 1955 8.69951 3.50116 5 1960 9.01457 3.68998 5 1965 9.04594 3.76410 5 1970 9.21074 4.05573 6 1955 9.37552 4.29114 6 1960 9.65188 4.59356 6 1965 10.21163 4.93361 6 1970 10.34039 5.25520 ; proc sort data=greene; by firm year; run; proc tscsreg data=greene; model cost = output; id firm year; run; /* Example 18.1 Analyzing Demand for Liquid Assets */ /* Chapter 18 page 889 */ data a; input state $ year d t s y rd rt rs; label d = 'Per Capita Demand Deposits' t = 'Per Capita Time Deposits' s = 'Per Capita S & L Association Shares' y = 'Permanent Per Capita Personal Income' rd = 'Service Charge on Demand Deposits' rt = 'Interest on Time Deposits' rs = 'Interest on S & L Association Shares'; cards; CA 1949 6.2785 6.1924 4.4998 7.2056 -1.0700 0.1080 1.0664 CA 1950 6.4019 6.2106 4.6821 7.2889 -1.0106 0.1501 1.0767 CA 1951 6.5058 6.2729 4.8598 7.3827 -1.0024 0.4008 1.1291 CA 1952 6.4785 6.2729 5.0039 7.4000 -0.9970 0.4492 1.1227 CA 1953 6.4118 6.2538 5.1761 7.4200 -0.8916 0.4662 1.2110 CA 1954 6.4520 6.2971 5.3613 7.4478 -0.6951 0.4756 1.1924 CA 1955 6.4998 6.3081 5.5452 7.4838 -0.7012 0.4929 1.2387 CA 1956 6.5162 6.2897 5.7236 7.5380 -0.6292 0.5636 1.2638 CA 1957 6.4646 6.3733 5.8579 7.5822 -0.4620 0.9712 1.3686 CA 1958 6.5191 6.4552 6.0331 7.6178 -0.4050 0.9712 1.3818 CA 1959 6.5709 6.4661 6.2025 7.6797 -0.4095 0.9738 1.3980 DC 1949 6.7499 5.4806 5.8230 7.3796 -1.3432 -0.3916 1.0307 DC 1950 6.9207 5.5413 5.9454 7.4804 -1.3205 -0.4125 1.0567 DC 1951 7.0775 5.6131 6.1420 7.6094 -1.3243 -0.3901 1.1006 DC 1952 6.9810 5.5452 6.2166 7.5606 -1.3205 -0.3161 1.0902 DC 1953 6.9117 5.5530 6.2971 7.5262 -1.2483 -0.1244 1.1102 DC 1954 6.9508 5.7203 6.4394 7.5326 -1.1777 0.4055 1.1259 DC 1955 6.9726 5.7961 6.5820 7.5658 -1.1457 0.4081 1.1559 DC 1956 6.9679 5.7991 6.6670 7.5761 -1.1332 0.4688 1.1787 DC 1957 7.0211 5.9687 6.8002 7.6425 -1.0613 0.8024 1.2143 DC 1958 7.0867 6.0799 6.9197 7.6704 -1.0217 0.7419 1.2404 DC 1959 7.0630 6.0014 7.0291 7.6811 -0.8723 0.8510 1.3156 FL 1949 6.0113 4.8363 4.6347 6.9315 -1.0385 -0.0954 0.8390 FL 1950 6.0707 4.8283 4.7274 6.9147 -1.0729 -0.0440 0.8446 FL 1951 6.1506 4.8903 4.9345 6.9735 -1.0936 0.0020 0.8871 FL 1952 6.1527 4.8828 5.1180 6.9735 -1.1147 0.0507 0.9466 FL 1953 6.1399 4.9273 5.2983 7.0370 -1.0385 0.1115 0.9651 FL 1954 6.1420 4.9416 5.5094 7.0361 -0.9835 0.2374 1.0547 FL 1955 6.3008 5.0814 5.8111 7.1747 -0.9729 0.2919 1.0585 FL 1956 6.3404 5.1120 5.9480 7.1997 -0.9188 0.3961 1.1092 FL 1957 6.2748 5.3660 6.0355 7.2320 -0.8052 0.8838 1.2054 FL 1958 6.2785 5.4806 6.1026 7.2506 -0.6972 0.8973 1.2099 FL 1959 6.2577 5.4596 6.2344 7.2841 -0.6482 0.9119 1.2740 IL 1949 6.7370 5.8749 4.7536 7.2896 -1.9449 -0.1602 0.9179 IL 1950 6.7569 5.8348 4.8363 7.2917 -1.9241 -0.1661 0.8953 IL 1951 6.7878 5.8141 4.9698 7.3492 -1.9173 -0.0661 0.8957 IL 1952 6.8178 5.9402 5.1648 7.4073 -1.9379 0.0573 0.9431 IL 1953 6.8123 5.9814 5.3423 7.4448 -1.8971 0.0871 0.9944 IL 1954 6.8330 6.0259 5.5334 7.4816 -1.8079 0.1222 1.0109 IL 1955 6.8448 6.0259 5.6904 7.5038 -1.7603 0.1319 1.0217 IL 1956 6.8501 6.0568 5.8579 7.5575 -1.6983 0.3031 1.0757 IL 1957 6.8013 6.0913 5.9713 7.5909 -1.5945 0.4874 1.1490 IL 1958 6.8233 6.1399 6.0958 7.6014 -1.5418 0.5522 1.2244 IL 1959 6.7731 6.1633 6.1924 7.6183 -1.4653 0.7198 1.2519 NY 1949 7.2226 5.6021 4.2047 7.3079 -2.1893 -0.3754 0.7415 NY 1950 7.2478 5.5645 4.2627 7.3232 -2.1286 -0.3230 0.7333 NY 1951 7.2506 5.5334 4.4427 7.3563 -2.1286 -0.2294 0.7966 NY 1952 7.2591 5.6058 4.6250 7.4140 -2.1203 0.0488 0.8899 NY 1953 7.2406 5.6904 4.7707 7.4639 -2.0099 0.2159 0.9070 NY 1954 7.2549 5.7621 4.9053 7.4967 -1.9310 0.2971 0.9322 NY 1955 7.2661 5.7462 5.0039 7.5000 -1.9241 0.3407 0.9764 NY 1956 7.2556 5.8260 5.1240 7.5580 -1.7838 0.5619 1.0203 NY 1957 7.2745 5.9915 5.2417 7.6372 -1.6660 0.8024 1.0842 NY 1958 7.2814 6.1137 5.3279 7.6592 -1.6503 0.8587 1.1227 NY 1959 7.2563 6.1181 5.4072 7.6948 -1.5945 0.9247 1.1703 TX 1949 6.3509 4.2341 3.5835 6.9027 -1.9038 -0.1755 1.0134 TX 1950 6.4520 4.2627 3.7377 6.9584 -1.9173 -0.1791 1.0080 TX 1951 6.5206 4.3438 3.8918 7.0510 -1.9105 -0.2083 1.0364 TX 1952 6.5043 4.4308 4.0604 7.0699 -1.9173 0.0677 1.0578 TX 1953 6.5013 4.5951 4.2905 7.1131 -1.8326 0.1570 1.1256 TX 1954 6.5624 4.7622 4.5218 7.1585 -1.7037 0.2837 1.1291 TX 1955 6.5820 4.8442 4.7095 7.1967 -1.6555 0.3133 1.1220 TX 1956 6.5624 4.8828 4.8203 7.2138 -1.5702 0.4344 1.1210 TX 1957 6.5147 5.0689 4.9698 7.2556 -1.3863 0.7519 1.2490 TX 1958 6.5737 5.3033 5.1059 7.2841 -1.2801 0.8069 1.2276 TX 1959 6.5554 5.3519 5.2781 7.3265 -1.1940 0.8899 1.3005 WA 1949 6.0355 5.3033 4.4998 7.0440 -1.0272 -0.0651 0.7266 WA 1950 6.2166 5.3753 4.6913 7.1884 -1.0189 -0.0274 0.8016 WA 1951 6.2634 5.3936 4.8520 7.2675 -1.0079 0.0383 0.8616 WA 1952 6.2519 5.4381 4.9698 7.3005 -0.9650 0.2662 0.9373 WA 1953 6.2146 5.4596 5.1591 7.3337 -0.8819 0.2942 1.0466 WA 1954 6.2860 5.5094 5.3613 7.3790 -0.7319 0.2986 1.0526 WA 1955 6.3008 5.5835 5.5053 7.4079 -0.6368 0.5710 1.0671 WA 1956 6.2634 5.5910 5.5722 7.4122 -0.5327 0.5761 1.1023 WA 1957 6.2025 5.6595 5.6525 7.4448 -0.3842 0.8385 1.1793 WA 1958 6.2558 5.7333 5.7621 7.4697 -0.3341 0.8338 1.1957 WA 1959 6.2442 5.7557 5.8435 7.5005 -0.3147 0.9143 1.2548 ; proc print data=a(obs=5); run; proc sort data=a; by state year; run; title 'Demand for Liquid Assets'; proc tscsreg data=a; model d = y rd rt rs / fuller parks dasilva m=7; model t = y rd rt rs / parks; model s = y rd rt rs / parks; id state year; run; /* Basic Seasonal Adjustment */ /* Chapter 19 page 898 */ title1; data sales; input sales @@; date = intnx( 'month', '01sep78'd, _n_-1 ); format date monyy.; cards; 112 118 132 129 121 135 148 148 136 119 104 118 115 126 141 135 125 149 170 170 158 133 114 140 145 150 178 163 172 178 199 199 184 162 146 166 171 180 193 181 183 218 230 242 209 191 172 194 196 196 236 235 229 243 264 272 237 211 180 201 204 188 235 227 234 264 302 293 259 229 203 229 242 233 267 269 270 315 364 347 312 274 237 278 284 277 317 313 318 374 413 405 355 306 271 306 315 301 356 348 355 422 465 467 404 347 305 336 340 318 362 348 363 435 491 505 404 359 310 337 360 342 406 396 420 472 548 559 463 407 362 405 417 391 419 461 472 535 622 606 508 461 390 432 run; proc x11 data=sales; monthly date=date; var sales; tables d11; run; title 'Monthly Retail Sales Data (in $1000)'; proc x11 data=sales noprint; monthly date=date; var sales; output out=out b1=sales d11=adjusted; run; symbol1 i=join v='plus'; symbol2 i=join v='diamond'; legend1 label=none value=('original' 'adjusted'); proc gplot data=out; plot sales * date = 1 adjusted * date = 2 / overlay legend=legend1; run; /* Example 19.1 Component Estimation - Monthly Data */ /* Chapter 19 page 933 */ title1; data sales; input sales @@; date = intnx( 'month', '01sep78'd, _n_-1 ); format date monyy.; cards; 112 118 132 129 121 135 148 148 136 119 104 118 115 126 141 135 125 149 170 170 158 133 114 140 145 150 178 163 172 178 199 199 184 162 146 166 171 180 193 181 183 218 230 242 209 191 172 194 196 196 236 235 229 243 264 272 237 211 180 201 204 188 235 227 234 264 302 293 259 229 203 229 242 233 267 269 270 315 364 347 312 274 237 278 284 277 317 313 318 374 413 405 355 306 271 306 315 301 356 348 355 422 465 467 404 347 305 336 340 318 362 348 363 435 491 505 404 359 310 337 360 342 406 396 420 472 548 559 463 407 362 405 417 391 419 461 472 535 622 606 508 461 390 432 run; proc x11 data=sales noprint; monthly date=date; var sales; tables b1 d11; output out=out b1=series d10=d10 d11=d11 d12=d12 d13=d13; run; symbol1 i=join v='plus'; symbol2 i=join v='diamond'; legend1 label=none value=('original' 'adjusted'); proc gplot data=out; plot series * date = 1 d11 * date = 2 / overlay legend=lengend1; run; symbol1 i=join v=diamond; proc gplot data=out; plot ( d10 d12 d13 ) * date; run; /* Example 19.2 Components Estimation - Quarterly Data */ /* Chapter 19 page 936 */ data quarter; input date yyq4. +1 fy35rr 5.2; format date yyq4.; cards; 71Q1 6.59 71Q2 6.01 71Q3 6.51 71Q4 6.18 72Q1 5.52 72Q2 5.59 72Q3 5.84 72Q4 6.33 73Q1 6.52 73Q2 7.35 73Q3 9.24 73Q4 10.08 74Q1 9.91 74Q2 11.15 74Q3 12.40 74Q4 11.64 75Q1 9.94 75Q2 8.16 75Q3 8.22 75Q4 8.29 76Q1 7.54 76Q2 7.44 76Q3 7.80 76Q4 7.28 run; proc x11 data=quarter; var fy35rr; quarterly date=date; tables b1 d11; output out=out b1=b1 d10=d10 d11=d11 d12=d12 d13=d13; run; /* Example 19.3 Outlier Detection and Removal */ /* Chapter 19 page 937 */ data a; retain seed 99831; do kk = 1 to 48; x = kk + 100 + rannor( seed ); date = intnx( 'month', '01jan70'd, kk-1 ); if kk = 20 then x = 2 * x; else if kk = 30 then x = x / 10; output; end; run; proc x11 data=a; monthly date=date additive fullweight=3.0 zeroweight=3.5; var x; table d9; output out=b b1=original e1=e1; run; symbol1 i=join v=plus; symbol2 i=join v=diamond; legend1 label=none value=('unmodified' 'modified'); proc gplot data= b; plot original * date = 1 e1 * date = 2 / overlay legend=legend1; format date monyy.; run;