/*------------------------------------------------------------ | Code1_1 | | Dates: Internally they are numbers 0=Jan 1, 1960 | | lag5(Y) is Y from 5 observations ago. | | Defining your F12 key | | (1) Tools-> Options -> Keys | | (2) At F12 type the following: | | log; clear; out; clear; wpgm; sub; | | (3) x - Close the Keys window | ------------------------------------------------------------*/ title " "; footnote " "; goptions reset=all; axis1 label=(angle=90 font=centb h=1.8) offset=(2,2); * libname fets "C:\Documents and Settings\dickey\Desktop\FETS\Data"; * (1) Check that data sets are OK; proc contents data=fets._all_ nods; run; * (2) Read and plot the data; data one; set fets.dotair9497; stored = date; days = date- '01dec1993'd; * SAS date constant; proc print data=one(obs=30); run; proc gplot data=one; plot passengers*date/vaxis=axis1;; symbol1 v=none i=join c=red; title "Airline"; run; * (3) Place Forecasts at proper Dates; Data two; set one; drop passengers stored days; slope12 = passengers-lag12(passengers); * 12 month change ; forecast12 = passengers + slope12; Method1 = passengers*(passengers/lag12(passengers)); if date > '01dec1994'd then do; date = intnx('month',date,12); * Bump date up by 12; keep date forecast12 Method1; end; proc print data=two(obs=30); run; Data three; merge one two; by date; proc print data=three(obs=30); run; * (4) Add the forecasts to plots; proc gplot; plot (passengers Forecast12 Method1)*date/ overlay vaxis=axis1 legend; title "Simple Forecast"; symbol2 v=dot i=join c=black; symbol3 v=diamond i=join c=green h=1.9; format passengers comma10.; run; * (5) Show linear trend Forecast; Proc reg data=three; model Passengers=date; output out=out1 predicted = reg; run; proc print data=out1; where date = "01jan1998"d; run; proc gplot; plot (passengers reg)*date/overlay; symbol2 v=none i=join; run; quit; title " "; footnote " ";