/*------------------------------------------------------------------*/ /* SAMPLE CODE */ /* */ /* SAS/ETS Software: Applications Guide 1, Version 6, First Edition */ /* Publication book code: 56008 */ /* */ /* Each sample begins with a comment that states the */ /* chapter and page number where the code is located. */ /*------------------------------------------------------------------*/ /* Chapter 1 page 11 */ /* Global statements apply to all */ /* examples in this section */ title 'Electricity Production Data'; title2 '(in thousands of kilowatt-hours)'; data electric; format date monyy5.; input date:monyy5. elec @@; month=date; cards; jan83 195579 feb83 172479 mar83 182488 apr83 170372 may83 174392 jun83 191048 jul83 220165 aug83 229957 sep83 195604 oct83 182931 nov83 182949 dec83 212319 jan84 216632 feb84 189564 mar84 200107 apr84 181084 may84 192217 jun84 209649 jul84 221245 aug84 229296 sep84 195198 oct84 190936 nov84 190380 dec84 199996 jan85 227856 feb85 198242 mar85 194970 apr85 184877 may85 196790 jun85 205363 jul85 226722 aug85 226050 sep85 202499 oct85 194789 nov85 192427 dec85 219255 jan86 217470 feb86 192336 mar86 196834 apr86 186074 may86 197315 jun86 215015 jul86 242672 aug86 225166 sep86 206692 oct86 197754 nov86 196432 dec86 213551 jan87 222749 feb87 194034 mar87 201849 apr87 189496 may87 206074 jun87 225589 jul87 247915 aug87 247645 sep87 213008 oct87 203009 nov87 200258 dec87 220500 jan88 237600 feb88 216702 mar88 213838 apr88 195809 may88 208180 jun88 232507 jul88 257235 aug88 267408 sep88 220023 oct88 210377 nov88 209394 dec88 232550 jan89 231343 feb89 219066 mar89 226436 apr89 207749 may89 219803 jun89 235397 jul89 256744 aug89 258335 ; proc print data=electric(obs=20); run; /* Chapter 1 page 13 */ goptions reset=global gunit=pct cback=white htitle=6 htext=3 ftext=swissb colors=(black); axis1 order=('01jan83'd to '01jan90'd by year) offset=(3) minor=(number=3); axis2 label=(angle=90 'Electricity Produced') order=(170000 to 270000 by 10000); proc gplot data=electric; plot elec*date / haxis=axis1 vaxis=axis2; format date year4.; symbol1 i=join; label date='Year'; run; /* Chapter 1 page 15 */ proc plot data=electric; format date year4.; format month monname1.; label date='Year' elec='Electricity Produced'; plot elec*date=month / haxis='01jan83'd to '01jan90'd by year; run; /* Chapter 2 page 21 */ data sales1; format date monyy5.; input date:monyy5. sales @@; cards; jan88 236 feb88 270 mar88 342 apr88 380 may88 212 jun88 461 jul88 400 aug88 337 sep88 379 oct88 298 nov88 431 dec88 . jan89 309 feb89 290 mar89 416 apr89 378 may89 501 jun89 . jul89 394 aug89 423 sep89 . oct89 487 nov89 519 dec89 322 jan90 . feb90 453 mar90 372 apr90 430 may90 544 jun90 401 ; proc print data=sales1; title 'Sales Data With 4 Missing Values'; run; /* Chapter 2 pages 22-23 */ /* interpolate missing data using default method */ /* create an output data set */ proc expand data=sales1 out=sales2 from=month; convert sales=newsales / observed=total; id date; run; /* print the output data set */ proc print data=sales2; title 'The SALES2 Output Data Set'; run; /* round off values in output data set */ data sales2; set sales2; newsales=round(newsales); run; /* Chapter 2 page 24 */ /* convert quarterly data to monthly data */ proc expand data=quarter out=monthly from=qtr to=month; convert sales=msales / observed=total; id date; run; /* round off values in output data set */ data monthly; set monthly; msales=round(msales); run; /* print the output data set */ proc print data=monthly; title 'The MONTHLY Output Data Set'; run; /* Chapter 2 page 25 */ /* convert monthly data to quarterly data */ proc expand data=monthly out=quarter1 from=month to=qtr; convert msales=qsales / observed=total; id date; run; proc print data=quarter1; title 'The QUARTER1 Output Data Set'; format date yyq.; run; /* Chapter 2 pages 26-27 */ /* change total data to average data */ proc expand data=monthly out=avmonth from=month; convert msales=avgsales / observed=(total,average); id date; run; data avmonth; set avmonth; avgsales=round(avgsales,.1); run; proc print data=avmonth; title 'The AVMONTH Output Data Set'; run; /* Chapter 2 pages 28-29 */ /* create a data set containing */ /* the exponential trend variable */ data expo; do time=0 to 10; x=2**time; output; end; run; proc gplot data=expo; title 'Exponential Trend'; plot x*time / hminor=0; symbol1 i=join; run; /* transform the exponential trend variable */ /* to a linear trend variable in a DATA step */ data trans; set expo; z=log(x); run; proc gplot data=trans; title 'Log Transformation'; plot z*time / hminor=0; symbol1 i=join; run; /* Chapter 2 page 32 */ /* use the INTNX function to create date values */ /* in a DATA step */ data monthly; input y @@; date=intnx('month','1jan90'd,_n_-1); format date monyy.; cards; 25 60 14 21 87 65 43 53 39 32 44 29 ; proc print data=monthly; title 'Using the INTNX Function'; id date; run; /* Chapter 3 page 41 */ proc arima data=electric; identify var=elec; run; /* Chapter 3 page 45 */ proc arima data=electric; identify var=elec; estimate p=1; run; /* Chapter 3 pages 50-51 */ /* Global statements apply to all */ /* examples in this section */ title 'Monthly U.S. Lead Production'; title2 '(in tons)'; data lead; input date:monyy. leadprod @@; format date monyy.; cards; jan81 57984 feb81 53569 mar81 58170 apr81 52741 may81 35038 jun81 24378 jul81 33027 aug81 45097 sep81 43704 oct81 46082 nov81 39412 dec81 44036 jan82 50257 feb82 45193 mar82 43994 apr82 36111 may82 54323 jun82 52974 jul82 44224 aug82 46362 sep82 49201 oct82 50574 nov82 50816 dec82 48585 jan83 57029 feb83 50943 mar83 52825 apr83 48938 may83 47230 jun83 42045 jul83 39525 aug83 45283 sep83 41226 oct83 49972 nov83 50886 dec83 46381 jan84 51500 feb84 51400 mar84 43000 apr84 40000 may84 39200 jun84 26200 jul84 28400 aug84 29100 sep84 25300 oct84 40800 nov84 28000 dec84 26500 jan85 43100 feb85 50300 mar85 56300 apr85 52700 may85 53400 jun85 50900 jul85 32500 aug85 46600 sep85 44900 oct85 39300 nov85 30100 dec85 44500 ; proc print data=lead(obs=20); run; axis1 order=('01jan81'd to '01jan86'd by year) offset=(3) minor=(number=3); axis2 order=(20000 to 60000 by 5000) label=(angle=90 'Lead Produced'); proc gplot data=lead; plot leadprod*date / haxis=axis1 vaxis=axis2; symbol1 i=join; format date year4.; label date='Year'; run; /* Chapter 3 page 52 */ proc arima data=lead; i var=leadprod; run; /* Chapter 3 pages 54-58 */ proc arima data=lead; i var=leadprod noprint; e p=1; run; e p=2; run; e p=1 method=uls; run; e p=1 method=ml; run; /* Chapter 3 page 59 */ proc autoreg data=lead; model leadprod= / nlag=1; run; /* Chapter 3 page 61 */ proc autoreg data=lead; model leadprod= / nlag=1 method=uls; run; /* Chapter 3 page 62 */ proc autoreg data=lead; model leadprod= / nlag=1 method=ml; run; /* Chapter 3 page 64 */ proc autoreg data=lead; model leadprod= / dwprob; run; /* Chapter 4 page 71 */ /* Global statements apply to all */ /* examples in this section */ title 'Dow Jones Industrials Index'; title2 'Monthly Average'; data djones; input date:monyy. dowjones @@; format date monyy.; cards; jan83 1064.29 feb83 1087.43 mar83 1129.58 apr83 1168.43 may83 1212.86 jun83 1221.47 jul83 1213.93 aug83 1189.21 sep83 1237.04 oct83 1252.20 nov83 1250.00 dec83 1257.64 jan84 1258.89 feb84 1164.46 mar84 1161.97 apr84 1152.71 may84 1143.42 jun84 1121.14 jul84 1113.27 aug84 1212.82 sep84 1213.51 oct84 1199.30 nov84 1211.30 dec84 1188.96 jan85 1238.16 feb85 1283.23 mar85 1268.83 apr85 1266.36 may85 1279.40 jun85 1314.00 jul85 1343.17 aug85 1326.18 sep85 1317.95 oct85 1351.58 nov85 1432.88 dec85 1517.02 jan86 1534.86 feb86 1652.73 mar86 1757.35 apr86 1807.05 may86 1801.80 jun86 1867.70 jul86 1809.92 aug86 1843.45 sep86 1813.47 oct86 1817.04 nov86 1883.65 dec86 1924.07 jan87 2065.13 feb87 2202.34 mar87 2292.61 apr87 2302.64 may87 2291.11 jun87 2384.02 jul87 2481.72 aug87 2655.01 sep87 2570.80 oct87 2224.59 nov87 1931.86 dec87 1910.07 jan88 1947.35 feb88 1980.65 mar88 2044.31 apr88 2036.13 may88 1988.91 jun88 2104.94 jul88 2104.22 aug88 2051.29 sep88 2080.06 oct88 2144.31 nov88 2099.04 dec88 2148.58 jan89 2234.68 feb89 2304.30 mar89 2283.11 apr89 2348.91 may89 2439.55 jun89 2494.90 jul89 2554.03 aug89 2691.11 sep89 2693.41 oct89 2692.01 ; proc print data=djones(obs=20); run; /* Chapter 4 page 72 */ axis1 order=('01jan83'd to '01jan90'd by year) offset=(3) minor=(number=3); axis2 order=(1000 to 2750 by 250) label=(angle=90 'Dow Jones Index'); proc gplot data=djones; plot dowjones*date / haxis=axis1 vaxis=axis2; symbol1 i=join; format date year4.; label date='Year'; run; /* Chapter 4 page 73 */ proc arima data=djones; i var=dowjones(1); run; /* Chapter 4 page 76 */ proc arima data=djones; i var=dowjones(1) noprint; e q=1; run; /* Chapter 4 pages 77-78 */ proc arima data=djones; i var=dowjones(1) noprint; e p=1; run; e q=2; e p=2; run; /* Chapter 5 page 86 */ proc arima data=djones; i var=dowjones; run; /* Chapter 5 page 87 */ data djones2; set djones; djdiff=dif(dowjones); run; /* Chapter 5 page 89 */ proc reg data=djones noprint; model dowjones=; output out=out1 r=res; run; data djtest; set out1; res1=lag(res); del=dif(dowjones); del1=lag(del); time=_n_-1; run; proc reg data=djtest; model del=time res1 del1; run; /* Chapter 5 page 90 */ proc reg data=djtest; model del=res1 del1/ noint; run; /* Chapter 6 page 94 */ /* Global statements apply to all */ /* examples in this chapter */ title 'Month-End Stocks of Gold'; title2 '(in troy ounces)'; data gold; input date:monyy. gold @@; format date monyy.; cards; jan82 2339542 feb82 2234863 mar82 2198347 apr82 2191251 may82 2188297 jun82 2048252 jul82 1984382 aug82 2004372 sep82 1974483 oct82 1956404 nov82 2139405 dec82 2243146 jan83 2430799 feb83 2736754 mar83 2645140 apr83 2649600 may83 2723413 jun83 2681667 jul83 2652038 aug83 2569583 sep83 2537731 oct83 2507263 nov83 2486838 dec83 2480670 jan84 2472175 feb84 2409992 mar84 2433703 apr84 2412696 may84 2426452 jun84 2414465 jul84 2400568 aug84 2403730 sep84 2390675 oct84 2361559 nov84 2356086 dec84 2307069 jan85 2276397 feb85 2297499 mar85 2109221 apr85 2136593 may85 2142318 jun85 2130142 jul85 2177708 aug85 2128244 sep85 2088402 oct85 2098525 nov85 2103542 dec85 2109817 jan86 2321369 feb86 2561832 mar86 2565172 apr86 2566940 may86 2196598 jun86 1992152 jul86 1623032 aug86 1664518 sep86 1726207 oct86 1787840 nov86 2149838 dec86 2890311 jan87 2798556 feb87 2817038 mar87 2905574 apr87 2621688 may87 2665310 jun87 2619309 jul87 2599963 aug87 2613385 sep87 2634492 oct87 2644554 nov87 2645346 dec87 2624565 jan88 2601145 feb88 2581355 mar88 1596566 apr88 1566414 may88 1675658 jun88 1706508 jul88 2099135 aug88 2179349 sep88 1949552 oct88 1629626 nov88 1267644 dec88 1434967 ; proc print data=gold(obs=20); run; /* Chapter 6 page 96 */ axis1 order=('01jan82'd to '01jan89'd by year) offset=(3) minor=(number=3); axis2 order=(1000000 to 3000000 by 200000) minor=(number=3); proc gplot data=gold; plot gold*date / haxis=axis1 vaxis=axis2; symbol1 i=join; format date year4.; label date='Year' gold='Stocks of Gold'; run; /* Chapter 6 pages 96-107 */ proc arima data=gold; i var=gold; run; i var=gold(1); run; e p=5; run; e p=(1,4); run; e p=1 q=(4); e p=(4) q=1; run; /* Chapter 7 page 115 */ /* Global statements apply to all */ /* examples in this chapter */ title 'Electricity Production Data (1972-89)'; title2 '(in thousands of kilowatt-hours)'; proc print data=electric(obs=20); run; /* Chapter 7 page 116 */ axis1 order=('01jan72'd to '05jan90'd by 731) label=('Year') minor=(number=1) offset=(3); axis2 order=(120000 to 270000 by 30000) minor=(number=2) label=(angle=90 'Electricity Produced'); proc gplot data=electric; plot elec*date / haxis=axis1 vaxis=axis2; symbol1 i=join; format date year4.; run; /* Chapter 7 pages 118-125 */ proc arima data=electric; i var=elec nlag=48; run; i var=elec(1,12) nlag=48; run; e q=(1)(12); run; e q=(1,2)(12); run; /* Chapter 8 page 132 */ /* Global statement applies to all */ /* examples in this chapter */ title 'Electricity Production Data (1983-89)'; proc x11 data=electric; monthly date=date; tables b1 d10 d11 d12; var elec; run; /* Chapter 8 page 136-137 */ proc x11 data=electric noprint; monthly date=date; var elec; output out=adjusted b1=original d10=season d11=adjust d12=trend; run; proc print data=adjusted(obs=20); title2 'PROC X11 Output Data Set'; run; /* Chapter 8 page 141 */ proc x11 data=electric; monthly date=date; tables b1 d10 d11 d12; var elec; arima; run; /* Chapter 8 page 145 */ proc x11 data=electric; monthly date=date printout=none charts=none; var elec; arima model=(q=1 sdif=1) forecast=1 backcast=1 method=ml printall nlag=12; run; /* Chapter 9 page 152-153 */ /* Global statement applies to all */ /* examples in this chapter */ title 'Construction Data'; data housecon; input date:monyy5. constr intrate hstarts @@; format date monyy5.; cards; JAN83 11358 13.00 91.3 FEB83 11355 12.62 96.3 MAR83 16100 12.97 134.6 APR83 16315 12.02 135.8 MAY83 19205 12.21 174.9 JUN83 20263 11.90 173.2 JUL83 16885 12.02 161.6 AUG83 19441 12.01 176.8 SEP83 17379 12.08 154.9 OCT83 16028 11.80 159.3 NOV83 15401 11.82 136.0 DEC83 13518 11.94 108.3 JAN84 14023 11.80 109.1 FEB84 14442 11.78 130.0 MAR84 17916 11.56 137.5 APR84 17655 11.55 172.7 MAY84 21990 11.68 180.7 JUN84 20036 11.61 184.0 JUL84 19224 11.91 162.1 AUG84 19367 11.89 147.4 SEP84 16923 12.03 148.5 OCT84 18413 12.27 152.3 NOV84 16616 12.27 126.2 DEC84 14220 12.05 98.9 JAN85 15154 11.77 105.4 FEB85 13652 11.74 95.8 MAR85 20004 11.42 145.2 APR85 20692 11.55 176.0 MAY85 22532 11.55 170.5 JUN85 20043 11.31 163.4 JUL85 22047 10.94 160.7 AUG85 21055 10.78 160.7 SEP85 20541 10.69 147.7 OCT85 21715 10.64 173.0 NOV85 17691 10.55 124.1 DEC85 16276 10.47 120.5 JAN86 15417 10.40 115.6 FEB86 16152 10.21 107.2 MAR86 19617 10.04 151.0 APR86 23754 9.87 188.2 MAY86 23050 9.84 186.6 JUN86 23740 9.74 183.6 JUL86 23621 9.89 172.0 AUG86 21884 9.84 163.8 SEP86 21763 9.74 154.0 OCT86 21862 9.57 154.8 NOV86 17998 9.45 115.6 DEC86 17982 9.28 113.0 JAN87 16694 9.14 105.1 FEB87 15729 8.87 102.8 MAR87 22622 8.77 141.2 APR87 23077 8.84 159.3 MAY87 22054 8.99 158.0 JUN87 25703 9.05 162.9 JUL87 24567 9.01 152.4 AUG87 23836 9.01 143.6 SEP87 22418 9.03 152.0 OCT87 23360 8.86 139.1 NOV87 18663 8.92 118.8 DEC87 19224 8.78 85.4 JAN88 15113 8.75 78.2 FEB88 17496 8.76 90.2 MAR88 22257 8.77 128.8 APR88 22344 8.76 153.2 MAY88 24138 8.59 140.2 JUN88 26940 8.90 150.2 JUL88 22309 8.80 137.0 AUG88 24826 8.68 136.8 SEP88 22670 8.90 131.1 OCT88 22223 8.77 135.1 NOV88 19767 9.05 113.0 DEC88 19125 9.04 94.2 JAN89 15776 9.20 100.1 FEB89 15086 9.46 85.8 MAR89 21080 9.63 117.8 APR89 21725 9.88 129.4 MAY89 23796 9.82 131.7 JUN89 24650 10.09 143.2 JUL89 22330 10.06 134.7 AUG89 24128 9.83 122.4 SEP89 23371 9.87 109.3 OCT89 22669 9.77 130.3 ; proc print data=housecon(obs=20); run; /* Chapter 9 page 156 */ proc autoreg data=housecon; model hstarts=constr intrate / nlag=2 method=ml; run; /* Chapter 9 page 158 */ data althouse; set housecon; time=_n_; run; proc autoreg data=althouse; model hstarts=constr intrate time / nlag=13 method=ml backstep; run; /* Chapter 9 page 160 */ proc autoreg data=housecon; model hstarts=constr intrate / nlag=2 method=ml noprint; output out=forecon p=forecast lcl=lower95 ucl=upper95; run; proc print data=forecon(firstobs=83); run; /* Chapter 9 page 162 */ proc arima data=housecon; i var=constr; i var=intrate; i var=hstarts; run; /* Chapter 9 pages 165-169 */ proc arima data=housecon; identify var=hstarts(12) crosscor=(constr(12) intrate(1)) nlag=15 noprint; run; estimate input=(constr intrate) plot method=ml; run; e input=(constr intrate) p=2 method=ml; run; e input=constr p=2 method=ml; run; /* Chapter 9 page 171 */ proc arima data=housecon; /* Identify and Estimate the Model */ i var=hstarts(12) crosscor=constr(12) nlag=15 noprint; e input=constr p=2 method=ml noprint; /* Invoke forecast phase */ forecast lead=12; run; /* Chapter 9 page 174 */ proc arima data=housecon; /* Model the Explanatory Variable */ identify var=constr(12) nlag=15 noprint; estimate p=(2,3) method=ml noprint; /* Estimate a Model for the Dependent Variable */ identify var=hstarts(12) crosscor=constr(12) nlag=15 noprint; estimate input=constr p=2 method=ml noprint; /* Forecast the Dependent Variable */ forecast lead=12; run; /* Chapter 9 pages 178-186 */ proc arima data=housecon; /* Identify Explanatory Variable */ identify var=constr(12) nlag=15 noprint; /* Estimate a Model for Explanatory Variable */ estimate p=(2,3) method=ml noprint; /* Print Cross-correlation Plot */ identify var=hstarts(12) crosscor=constr(12) nlag=12; run; estimate input=(/(1) constr) method=ml plot; run; estimate p=(2,5) input=(/(1) constr) method=ml; run; forecast lead=12; run; /* Chapter 10 page 193 */ proc statespace data=lead; var leadprod; run; /* Chapter 10 page 197 */ data housecon; set housecon; constrl=log(constr); hstartl=log(hstarts); run; proc statespace data=housecon noest; var hstartl(12) constrl(12); run; /* Chapter 10 page 199 */ proc statespace data=housecon; var hstartl(12) constrl(12); run; /* Chapter 10 page 200 */ proc statespace data=housecon; var hstartl(12) constrl(12); restrict f(1,2)=0 g(3,2)=0; run; /* Chapter 10 page 203 */ proc statespace data=housecon lead=12 printout=none out=fore1; var hstartl(12) constrl(12); restrict f(1,2)=0 g(3,2)=0; run; proc print data=fore1(firstobs=71); title 'The FORE1 Output Data Set'; run; /* Chapter 10 page 204 */ data fore1; set fore1; forehst=exp(for1); forecon=exp(for2); run; proc print data=fore1(firstobs=83); title 'Forecasts of Construction Data'; var forehst forecon; run; /* Chapter 11 page 215 */ proc spectra data=lead out=speclead p s adjmean; var leadprod; weights 1 2 3 4 3 2 1; run; proc print data=speclead; title 'SPECLEAD Output Data Set'; run; /* Chapter 11 page 216 */ axis1 order=(0 to 3.5 by .5) length=80 label=('Frequency'); axis2 order=(0 to 900000000 by 100000000) label=(angle=90 'Periodogram of LEADPROD'); proc gplot data=speclead; plot p_01*freq / haxis=axis1 hminor=0 vaxis=axis2 vminor=3; symbol1 i=join; title 'Lead Production Data'; title2 'Periodogram'; run; /* Chapter 11 page 217 */ axis1 order=(0 to 3.5 by .5) length=80 label=('Frequency'); axis2 order=(0 to 40000000 by 5000000) label=(angle=90 'Spectral Density of LEADPROD'); proc gplot data=speclead; plot s_01*freq / haxis=axis1 hminor=0 vaxis=axis2 vminor=4; symbol1 i=join; title 'Lead Production Data'; title2 'Spectral Density Estimates'; run; /* Chapter 11 pages 218-219 */ data elec2; set electric; elecd=dif(dif12(elec)); if elecd=. then delete; run; proc spectra data=elec2 out=specelec s adjmean; var elecd; weights 1 2 3 4 5 6 7 6 5 4 3 2 1; run; axis1 order=(2 to 14 by 2) offset=(3) minor=(number=3); axis2 order=(0 to 20000000 by 2000000) minor=(number=3) label=(angle=90 'Spectral Density'); proc gplot data=specelec; plot s_01*period / haxis=axis1 vaxis=axis2; symbol1 i=join; label period='Period'; title 'Electricity Production (1972-1989)'; title2 'Spectral Density Estimates'; run; /* Chapter 11 page 220 */ proc spectra data=lead whitetest; var leadprod; run; /* Chapter 12 pages 228-229 */ data leadadd(drop=i); set lead end=eof; output; if eof then do i=1 to 12; leadprod=.; date=intnx('month',date,1); output; end; run; proc autoreg data=leadadd; model leadprod= / nlag=1 method=ml noprint; output out=leadf p=forecast lcl=lower95 ucl=upper95; run; proc print data=leadf(firstobs=61); title 'LEADF Output Data Set'; run; /* Chapter 12 page 230 */ symbol1 h=2 pct v=A font=swissb color=black; symbol2 i=join l=1 color=black; symbol3 i=join l=20 color=black; symbol4 i=join l=20 color=black; axis1 order=('01jan81'd to '01jan87'd by year) offset=(3) minor=(number=3); axis2 label=(angle=90 'Lead Produced') order=(15000 to 70000 by 5000); proc gplot data=leadf; plot leadprod*date forecast*date=2 lower95*date=3 upper95*date=4 / overlay haxis=axis1 vaxis=axis2 vminor=4; format date year4.; label date='Year'; title 'Monthly U.S. Lead Production'; title2 '(in tons)'; run; /* Chapter 12 page 232 */ proc autoreg data=leadadd; model leadprod= / nlag=1 method=uls noprint; output out=leadf2 p=forecast lcl=lower95 ucl=upper95; run; proc print data=leadf2(firstobs=61); title 'LEADF2 Output Data Set'; run; /* Chapter 12 page 232 */ proc autoreg data=leadadd; model leadprod= / nlag=1 method=yw noprint; output out=leadf3 p=forecast lcl=lower95 ucl=upper95; run; proc print data=leadf3(firstobs=61); title 'LEADF3 Output Data Set'; run; /* Chapter 12 pages 234-237 */ proc arima data=lead; identify var=leadprod noprint; estimate p=1 method=ml noprint; forecast lead=12; run; e p=1 method=uls noprint; f lead=12; run; e p=1 method=cls noprint; f lead=12; run; /* Chapter 12 page 240 */ proc forecast data=lead nlags=1 interval=month trend=1 out=fore1 outall; id date; var leadprod; run; proc print data=fore1(firstobs=178); title 'FORE1 Output Data Set'; run; /* Chapter 12 pages 243-245 */ proc forecast data=housecon interval=month out=housef outlimit outest=esthouse; id date; var constr hstarts intrate; run; proc print data=esthouse; title 'ESTHOUSE Output Data Set'; run; proc print data=housef; title 'HOUSEF Output Data Set'; run; /* Chapter 13 page 252 */ data books; title 'Book Sales Data'; title2 '(in units)'; date=intnx('month','1jan88'd,_n_); format date monyy5.; input sales @@; cards; 1048 2044 1865 817 1128 1497 1454 625 576 1202 1121 970 404 540 300 449 639 1244 928 524 395 541 717 816 381 326 268 369 230 1265 737 411 234 774 496 679 464 365 266 ; /* Chapter 13 page 254 */ proc arima data=books; i var=sales(1) noprint; e q=1 noconstant; f lead=8; run; /* Chapter 13 page 257 */ proc forecast data=books method=expo trend=1 lead=8 interval=month weight=.25969 out=bookf1 outstd; var sales; id date; run; proc print data=bookf1; run; /* Chapter 13 page 258 */ proc forecast data=books method=expo trend=2 interval=month lead=8 out=bookf2 outactual outlimit; var sales; id date; run; proc print data=bookf2(firstobs=40); run; /* Chapter 13 page 259 */ axis1 order=('01jan88'd to '01jan92'd by year) minor=(number=3) offset=(2); axis2 order=(-800 to 2400 by 400) minor=(number=3) label=(angle=90 'Books Sold'); symbol1 l=1 i=join color=black; symbol2 h=2 v=F pct color=black; symbol3 l=20 i=join color=black; symbol4 l=20 i=join color=black; proc gplot data=bookf2; plot sales*date=_type_ / haxis=axis1 vaxis=axis2 href='15apr91'd lh=34 ch=black; format date year4.; label date='Year' _type_='Observation Type'; run; /* Chapter 13 page 260 */ proc transpose data=bookf2(drop=_lead_) out=tbookf2(drop=_name_); id _type_; by date; run; proc print data=tbookf2(firstobs=36); run; /* Chapter 13 pages 261-262 */ proc forecast data=books method=expo interval=month lead=8 out=bookf3 outest=estbook; var sales; id date; run; proc print data=bookf3; run; proc print data=estbook; run; /* Chapter 13 page 265 */ proc arima data=djones; identify var=dowjones(1) noprint; estimate q=1 method=ml noprint; forecast lead=12 out=dowf id=date interval=month; run; /* Chapter 14 pages 276-277 */ proc forecast data=housecon method=winters seasons=month interval=month out=fore1 outest=fore2 outstd outlimit; var constr hstarts intrate; id date; run; proc print data=fore1; run; proc print data=fore2; run; /* Chapter 14 pages 281-282 */ proc forecast data=housecon method=addwinters seasons=month interval=month out=fore1 outest=fore2 outstd outlimit; var constr hstarts intrate; id date; run; proc print data=fore1; run; proc print data=fore2; run; /* Chapter 15 pages 290-292 */ proc arima data=electric; identify var=elec(1,12) nlag=48 noprint; estimate q=(1,2)(12) method=ml noprint; forecast lead=12 out=elecf id=date interval=month; run; proc print data=elecf(firstobs=212); run; /* Chapter 15 page 293 */ symbol1 i=join color=black; symbol2 h=2 pct v=F font=swissb color=black; symbol3 i=join l=20 color=black; symbol4 i=join l=20 color=black; axis1 order=('01jan88'd to '01jan91'd by year) minor=(number=3) offset=(3); axis2 label=(angle=90 'Electricity Produced') order=(180000 to 300000 by 10000) minor=(number=1); proc gplot data=elecf(where=(date ge '01jan88'd)); plot elec*date=1 forecast*date=2 l95*date=3 u95*date=4 / overlay haxis=axis1 vaxis=axis2; format date year4.; label date='Year'; title 'Electricity Production Data'; run; /* Chapter 15 pages 294-296 */ data elecadd(drop=i); set electric end=eof; output; if eof then do i=1 to 12; elec=.; date=intnx('month',date,1); output; end; run; data elec2; set elecadd; array seasons{12} s_jan s_feb s_mar s_apr s_may s_jun s_jul s_aug s_sep s_oct s_nov s_dec; do i=1 to 12; if mod(_n_,12)=i then seasons{i}=1; else seasons{i}=0; if mod(_n_,12)=0 then seasons{12}=1; else seasons{12}=0; end; time=_n_; run; proc autoreg data=elec2; model elec=s_jan s_feb s_mar s_apr s_may s_jun s_jul s_aug s_sep s_oct s_nov s_dec time / noint nlag=3 method=ml; run; /* Chapter 15 pages 298-299 */ proc autoreg data=elec2; model elec=s_jan s_feb s_mar s_apr s_may s_jun s_jul s_aug s_sep s_oct s_nov s_dec time / noint nlag=1 method=ml; output out=elecf2 p=forecast lcl=lower95 ucl=upper95; run; proc print data=elecf2(firstobs=213); run; /* Chapter 15 page 302 */ /* Calculate Forecasts and Confidence Limits */ /* Create Output Data Set, ELECF */ proc arima data=electric; identify var=elec(1,12) nlag=48 noprint; estimate q=(1,2)(12) method=ml noprint; forecast lead=12 out=elecf id=date interval=month noprint; run; /* Calculate Seasonal Factors */ /* Create Output Data Set, SEASONS */ proc x11 data=electric yraheadout; monthly date=date printout=none charts=none; output out=seasons d10=seasfact; var elec; run; /* Create New Data Set */ /* Merge ELECF and SEASONS */ /* Divide Forecasts by Seasonal Factors */ data adjust; merge elecf seasons; by date; adjcast=100*forecast/seasfact; run; proc print data=adjust(firstobs=201); var date adjcast ; run; /* Chapter 16 page 311 */ data sales; input date monyy. product $ boston newyork atlanta; format date monyy.; cards; jan90 A 31 39 60 jan90 B 15 96 9 jan90 C 21 6 10 feb90 A 29 37 51 feb90 B 22 72 12 feb90 C 19 17 14 mar90 A 34 36 60 mar90 B 42 65 21 mar90 C 32 35 21 apr90 A 33 49 70 apr90 B 36 72 18 apr90 C 23 42 17 may90 A 31 39 68 may90 B 38 91 14 may90 C 18 31 24 jun90 A 38 31 64 jun90 B 27 104 24 jun90 C 30 39 19 ; run; proc print data=sales; title 'ABC Manufacturing, Inc.'; run; /* Chapter 16 pages 312-313 */ proc sort data=sales out=sales1; by product; run; proc print data=sales1 split='*'; options ps=45; var date atlanta boston newyork; by product; id product; sum atlanta boston newyork; label atlanta='Sales for*Atlanta*Region' boston='Sales for*Boston*Region' newyork='Sales for*New York*Region'; format atlanta boston newyork dollar6.; title 'ABC Manufacturing, Inc.'; title2 'Sales Report'; footnote 'sales in $000'; run; /* Chapter 16 page 314 */ proc computab data=sales; title 'ABC Manufacturing, Inc.'; run; /* Chapter 16 page 315 */ proc computab data=sales sumonly; by date; sumby _total_ date; title 'ABC Manufacturing, Inc.'; title2 'Monthly Sales Reports and Summary'; title3 '(sales in $000)'; /* Column Specification and Selection */; columns a b c total / format=5.; a=(product='A'); b=(product='B'); c=(product='C'); /* Create a New Column */; col: total=a+b+c; /* Row Specification */; rows atlanta / 'Atlanta'; rows boston / 'Boston'; rows newyork / 'New York' ul; rows sum; /* Create a New Row */; row: sum=atlanta+boston+newyork; run; /* Chapter 16 pages 317-318 */ data income; input sales retdis cogs smarket admin research deprec other; cards; 1996 116 750 171 132 290 80 18 ; run; proc computab data=income; title 'ABC Manufacturing, Inc.'; title2 'Income Statement'; title3 'Six-Month Period Ending June 30, 1990'; footnote '(Amounts in $000)'; options ps=40; /* Specify Column Label and Format */; columns col1 / ' ' format=comma7.; /* Input Column with Column Selection Technique */; _col_=1; /* Specify Rows and Row Labels */; rows sales / 'Gross Sales'; rows retdis / 'Less Returns and Discounts' ul; rows netsales / 'Net Sales' +3; rows cogs / ' ' 'Cost of Goods Sold' ul; rows gprofit / 'Gross Profit'; rows smarket / ' ' 'Operating Expenses:' ' Sales and Marketing'; rows admin / ' Administrative'; rows research / ' Research and Development'; rows deprec / ' Depreciation' ul; rows operexp / ' Total Operating Expenses' ul; rows operinc / 'Operating Income'; rows other / 'Other Income/(-Expense)' ul; rows taxinc / 'Taxable Income'; rows taxes / 'Income Taxes @ 40%' ul; rows netinc / ' Net Income' dul; /* Calculate New Rows */; rowcalc: netsales=sales-retdis; gprofit=netsales-cogs; operexp=smarket+admin+research+deprec; operinc=gprofit-operexp; taxinc=operinc+other; taxes=.40*taxinc; netinc=taxinc-taxes; run; /* Chapter 16 page 319 */ data balance; input year $ cash stinv acctrec inven prepaid / land bldgs equip oprop deprec patents / ltnotes oassets loans acctpay wages pensions / oaccrue taxes mature deftax ltdebt pfstock / common excess retearn adjust tshares; cards; 1989 4851 2358 56653 71925 5997 4380 44426 71536 11492 61574 1599 3912 1531 10956 23683 7017 2504 7523 3995 3166 4324 69868 0 17690 21064 64256 -559 16401 1990 2246 12626 48796 56801 6996 4651 50881 75580 11777 68154 1507 3338 1773 3274 17255 6204 2718 9884 1032 5903 5922 71100 0 17690 21029 64710 -1652 16251 ; run; proc print data=balance; title 'ABC Manufacturing, Inc.'; title2 'Balance Sheet Data Verification'; title3 'with PROC PRINT'; run; /* Chapter 16 page 320 */ proc computab data=balance; title 'ABC Manufacturing, Inc.'; title2 'Balance Sheet Data Verification'; title3 'with PROC COMPUTAB'; /* Column Specification and Selection */; columns y1989 y1990 / format=dollar8. ; y1989=(year='1989'); y1990=(year='1990'); run; /* Chapter 16 pages 320-322 */ proc computab data=balance; title 'ABC Manufacturing, Inc.'; title2 'Consolidated Balance Sheet'; title3 'Amounts in thousands'; /* Column Specification and Selection */; columns y1989 y1990 / mtitle=' December 31' format=dollar8. zero='-'; columns y1989 / '1989'; columns y1990 / '1990'; y1989=(year='1989'); y1990=(year='1990'); /* Row Specification */; rows cash / 'ASSETS' 'CURRENT ASSETS' 'Cash'; rows stinv / 'Short-term Investments, at cost'; rows acctrec / 'Notes and Accounts Receivable'; rows inven / 'Inventories'; rows prepaid / 'Prepaid Expenses' ul; rows totcura / ' Total Current Assets' ul; rows land / ' ' 'PROPERTY, PLANT, AND EQUIPMENT' 'Land'; rows bldgs / 'Buildings'; rows equip / 'Machinery and Equipment'; rows oprop / 'Other' ul; rows subprop / ' '; rows deprec / 'Less Accumulated Depreciation' ' and Amortization' ul; rows netprop / ' Net Property, Plant, and Equipment' ul; rows patents / ' ' 'OTHER ASSETS' 'Patents, Trademarks, and Licenses, net'; rows ltnotes / 'Long-term Notes Receivable'; rows oassets / 'Other' ul; rows sumother / ' ' ul; rows totass / ' TOTAL ASSETS' dul; rows loans / ' ' "LIABILITIES AND SHAREHOLDER'S EQUITY" 'CURRENT LIABILITIES' 'Notes and Loans Payable'; rows acctpay / 'Accounts Payable'; rows wages / 'Wages, Salaries, and Commissions'; rows pensions / 'Accrued Pension Expense'; rows oaccrue / 'Other Accrued Liabilities'; rows taxes / 'Income Taxes'; rows mature / 'Current Maturities of Long-term Debt' ul; rows totcurl / ' Total Current Liabilities' ul; rows deftax / ' ' 'DEFERRED INCOME TAXES'; rows ltdebt / ' ' 'LONG-TERM DEBT'; rows pfstock / ' ' "SHAREHOLDER'S EQUITY" ' ' 'Preferred Stock, $100 par value;' ' 200,000 shares authorized; none issued'; rows common / 'Common Stock, $2.50 par value;' ' 10,000,000 shares authorized;' ' 7,076,170 issued'; rows excess / 'Capital in Excess of par value'; rows retearn / 'Retained Earnings'; rows adjust / 'Equity adjustment from foreign' ' currency translation' ul; rows subeq / ' '; rows tshares / 'Less cost of treasury shares: ' ' 1990 - 951,448 shares; 1989 - 960,214 shares' ul ; rows toteq / " Total Shareholder's Equity" ul; rows totleq / " TOTAL LIABILITIES AND SHAREHOLDER'S EQUITY" dul; /* calculate new rows */; rowcalc: totcura=cash+stinv+acctrec+inven+prepaid; subprop=land+bldgs+equip+oprop; netprop=subprop-deprec; sumother=patents+ltnotes+oassets; totass=totcura+netprop+sumother; totcurl=loans+acctpay+wages+pensions+oaccrue+taxes+mature; subeq=pfstock+common+excess+retearn+adjust; toteq=subeq-tshares; totleq=totcurl+deftax+ltdebt+toteq; run; /* Chapter 17 page 331 */ proc loan; fixed amount=10000 life=36 rate=12 downpayment=2000 label='12% Fixed Rate Loan, 36 Months' schedule; run; /* Chapter 17 page 334 */ proc mortgage amount=10000 life=36 rate=.12 firstpayment=1992:6; run; /* Chapter 17 page 334 */ proc loan; fixed a=7055.88 /* principal remaining after the first year */ p=332.14 r=12 prepayments=100 start=1993:5 /* prepayments will start in June */ schedule label='12% Fixed,3 Yr, $100 Prepaid After Yr 1'; run; /* Chapter 17 page 336 */ proc loan; fixed a=10000 l=24 r=04 label='4% Fixed Rate Loan, 24 Months'; run; /* Chapter 17 page 338 */ proc loan interval=month; fixed amount=10000 life=36 rate=12 downpayment=2000 compound=semiyear label='Canadian Interest Calculation'; run; /* Chapter 17 page 339 */ proc loan; /* specify an adjustable rate mortgage */ arm a=115625 /* $125,000 - $9,375 = loan amount */ downpayment=9375 /* downpayment as a dollar value */ points=1875 /* payment for points as a dollar value */ l=360 r=08 caps=(.02, .05) /* the interest rate annual and lifetime caps */ adjustfreq=12 /* the frequency of interest adjustment */ worstcase /* specifies worstcase scenario */ label='Worst Case ARM'; run; /* Chapter 17 page 342 */ proc loan start=1992:3; arm a=115625 downpayment=9375 points=1875 l=360 r=08 caps=(.02, .05) adjustfreq=12 estimatedcase=(48=.1 60=.12 72=.13) label='ARM Estimated Case'; run; /* Chapter 17 page 344 */ proc loan; /* specify the first loan */ balloon a=135000 downpayment=15000 l=360 r=0975 balloonpayment=(84=2000) label='Balloon Loan'; /* specify the second loan */ arm a=135000 downpayment=15000 l=360 r=08 caps=(.02, .06) adjustfreq=12 worstcase label='Worst Case ARM Loan'; /* compare the loans at the end of yrs 1,2,3,7 */ compare at=(12 24 36 84); run; /* Chapter 17 page 349-350 */ proc loan noprint; /* the NOPRINT option suppresses all printed output */ /* specify the first loan, a balloon loan */ balloon a=135000 downpayment=15000 l=360 r=0975 balloonpayment=(84=2000) outsum=ballsum /* write summary of balloon loan to output data set named BALLSUM */ out=ball_out; /* write balloon loan amortization schedule to output data set named BALL_OUT */ /* specify the second loan, an adjustable rate mortgage */ arm a=135000 downpayment=15000 l=360 r=08 caps=(.02, .06) adjustfreq=12 worstcase outsum=armsum /* write summary of ARM loan to output data set named ARMSUM */ out=arm_out; /* write ARM amortization schedule to output data set named ARM_OUT */ compare at=(12 24 36) /* compare at the end of yrs 1,2,& 3 */ outcomp=compare; /* write loan comparison analysis to output data set named COMPARE */ run; proc print data=ball_out(obs=15); /* print first 15 obs from the ball_out data set */ title 'Balloon Loan Payment Schedule'; run; /* Appendix 1 pages 355-356 */ data electric; format date monyy5.; input date:monyy5. elec @@; cards; jan72 144549 feb72 137310 mar72 140151 apr72 132112 may72 138168 jun72 145583 jul72 157878 aug72 162901 sep72 147584 oct72 144062 nov72 144366 dec72 154966 jan73 159913 feb73 143257 mar73 147846 apr73 139292 may73 147088 jun73 160945 jul73 173467 aug73 177109 sep73 156385 oct73 153951 nov73 147881 dec73 153305 jan74 157254 feb74 142472 mar74 150043 apr74 142021 may74 153513 jun74 156161 jul74 177992 aug74 173871 sep74 152222 oct74 151978 nov74 149841 dec74 159736 jan75 164325 feb75 147080 mar75 155481 apr75 146217 may75 153231 jun75 162442 jul75 176816 aug75 179714 sep75 155223 oct75 154944 nov75 152794 dec75 169372 jan76 178329 feb76 156684 mar76 164174 apr76 153167 may76 157370 jun76 173392 jul76 186434 aug76 186403 sep76 165035 oct76 163746 nov76 169085 dec76 183877 jan77 196372 feb77 162734 mar77 169157 apr77 156853 may77 169332 jun77 180787 jul77 198930 aug77 196126 sep77 176265 oct77 166402 nov77 167099 dec77 184267 jan78 197835 feb78 173504 mar78 173193 apr78 159738 may78 175236 jun78 188312 jul78 202682 aug78 206418 sep78 185572 oct78 175802 nov78 176172 dec78 191865 jan79 209692 feb79 186337 mar79 182849 apr79 169962 may79 178069 jun79 186682 jul79 202255 aug79 204850 sep79 180751 oct79 179716 nov79 177506 dec79 188703 jan80 200005 feb80 188715 mar80 187464 apr80 168720 may80 175734 jun80 189430 jul80 216776 aug80 215393 sep80 191485 oct80 178555 nov80 178550 dec80 195613 jan81 206467 feb81 179613 mar81 185553 apr81 172545 may81 177806 jun81 202702 jul81 220373 aug81 210403 sep81 186838 oct81 181352 nov81 175570 dec81 195590 jan82 209403 feb82 180299 mar82 187687 apr82 172580 may82 177147 jun82 186128 jul82 210584 aug82 205656 sep82 180662 oct82 172966 nov82 173377 dec82 184722 jan83 195579 feb83 172479 mar83 182488 apr83 170372 may83 174392 jun83 191048 jul83 220165 aug83 229957 sep83 195604 oct83 182931 nov83 182949 dec83 212319 jan84 216632 feb84 189564 mar84 200107 apr84 181084 may84 192217 jun84 209649 jul84 221245 aug84 229296 sep84 195198 oct84 190936 nov84 190380 dec84 199996 jan85 227856 feb85 198242 mar85 194970 apr85 184877 may85 196790 jun85 205363 jul85 226722 aug85 226050 sep85 202499 oct85 194789 nov85 192427 dec85 219255 jan86 217470 feb86 192336 mar86 196834 apr86 186074 may86 197315 jun86 215015 jul86 242672 aug86 225166 sep86 206692 oct86 197754 nov86 196432 dec86 213551 jan87 222749 feb87 194034 mar87 201849 apr87 189496 may87 206074 jun87 225589 jul87 247915 aug87 247645 sep87 213008 oct87 203009 nov87 200258 dec87 220500 jan88 237600 feb88 216702 mar88 213838 apr88 195809 may88 208180 jun88 232507 jul88 257235 aug88 267408 sep88 220023 oct88 210377 nov88 209394 dec88 232550 jan89 231343 feb89 219066 mar89 226436 apr89 207749 may89 219803 jun89 235397 jul89 256744 aug89 258335 ;