Graphic visualization of time series variables is helpful in identifying and interpreting relationships in data. High resolution color graphics plots convey the information quickly and concisely. This example makes use of the ODS graphics for PROC ARIMA and compares them to the graphics produced using the GPLOT procedure. The user will be able to plot forecasts and the associated 95% confidence band for an intervention model of driver casualties (deaths and serious injuries) in road accidents in Great Britain. The intervention variable is the passage of a mandatory seatbelt law in January, 1983.
In January 1983, the British government passed a mandatory seatbelt law in order to reduce the number of casualties in road accidents. Seatbelt laws are often controversial. Opponents sometimes claim that they do not significantly reduce the number of casualties. A graphical analysis of the forecasted values and the upper and lower 95% confidence limits from an intervention model gives us valuable insights into the impact of the legislation. The driver casualties are taken from Harvey (1989). The INJURIES variable contains the number of deaths and serious injuries to car drivers on roads in Great Britain from January 1980 to December 1984. Twelve missing values are added to the end of the data set for use in the example. In January 1983, a mandatory seatbelt law took effect. The BELTLAW variable takes on the value 0 before January 1, 1983, and a value of 1 thereafter.
data drivers; format date monyy.; input date:monyy5. injuries @@; beltlaw = (date ge '01jan83'd); datalines; jan80 1665 feb80 1361 mar80 1506 apr80 1360 may80 1453 jun80 1522 jul80 1460 aug80 1552 sep80 1548 oct80 1827 nov80 1737 dec80 1941 jan81 1474 feb81 1458 mar81 1542 apr81 1404 ... more lines ... sep84 1444 oct84 1575 nov84 1737 dec84 1763 jan85 . feb85 . mar85 . apr85 . may85 . jun85 . jul85 . aug85 . sep85 . oct85 . nov85 . dec85 . ; run;
The intervention model is estimated with the ARIMA procedure. Briefly, the procedure uses the input data set DRIVERS. The I statement identifies the variable INJURIES, the E statement estimates the ARIMA model specified, and the F statement outputs monthly forecasts to the output data set, FORE2. For a more thorough analysis of the intricacies of working with ARIMA models, see (http://support.sas.com/rnd/app/examples/ets/sarma/index.htm) for forecasting a Seasonal ARMA Process.
Before the introduction of ODS graphics, the GPLOT procedure had been used on many different levels. Simple plots can be produced with ease; for instance, the time series plot in Figure 1.1 of the variable INJURIES can be produced with the following statement:
proc gplot data=drivers; plot injuries*date=1; symbol1 v=star c=blue; title "Time Series Plot"; run; quit; title;
Figure 1.1 Simple Time Series Plot of INJURIES
In the past, to achieve professional quality graphics, you would have run the ARIMA procedure, saved the output into a DATA set, and used the output in the GPLOT procedure. This would have required some formatting to achieve professional quality graphics. The following code produces the forecast plot in Figure 1.2 using the ARIMA and GPLOT procedures.
proc arima data=drivers; i var=injuries crosscorr=beltlaw noprint; e input=beltlaw p=(1)(2 12); f lead=12 out=fore2 id=date interval=month; run; quit;
goptions cback=white ctitle=bl ctext=bl ftitle=centx ftext=centx reset=(axis symbol); proc gplot data=fore2; format date year4.; plot injuries*date=1 forecast*date=2 l95*date =3 u95*date =3 / overlay haxis=axis1 vaxis=axis2 vminor=4 href='01jan83'd lh=2; title 'Driver Casualties Data'; title2 'Monthly Totals'; axis1 offset=(1 cm) label=('Year') order=('01jan80'd to '01jan86'd by year); axis2 label=(angle=90 'Casualties') order=(750 to 2250 by 500); symbol1 i=join l=1 c=red; symbol2 h=2 pct v=star c=blue; symbol3 l=20 i=join c=green; footnote1 c=r f=centx ' --- Actual' c=b f=centx ' * Forecast' c=g f=centx ' --- U95/L95'; run; quit; title; footnote;
Figure 1.2 Forecast Plot Produced by PROC GPLOT
It is always good form to specify the formating options for your graph in the GOPTIONS statement. The CBACK= option sets the color of the background, while the CTITLE= and CTEXT= options enable you to choose a font from among the many supported by SAS/GRAPH software for the title and text. In this example, the CENTX (Century Expanded) font is used for both the title and text. The RESET= option resets the title and the text.
The axes can be formatted using the AXISn definitions. The OFFSET= option specifies the amount of space to offset the first and last major tick marks from the origin and end of the axis. The LABEL= option enables you to label each axis in the graph. The ANGLE=90 option in the AXIS2 statement rotates the label 90 degrees. The ORDER= option specifies the data values in the order in which they are to appear on the axis.
The SYMBOL definitions are used to specify the shape (V= option), as well as the size (H= ) and color (C= ), of the plot symbols used to mark the data points. The I= option enables you to interpolate between data points by a number of methods. The type of line used is specified with the L= option. A value of L=1 corresponds to a solid line, while L=20 is a dashed line.
Footnotes can be used to provide additional information. In this example, a footnote is used to add a legend to the plot.
The GPLOT procedure uses the input data set FORE2. The OVERLAY option in the PLOT statement plots the time series INJURIES, FORECAST, L95, and U95 on the same graph using the symbols indicated. The HAXIS and VAXIS options specify the horizontal and vertical axes to be used in the plot. The VMINOR=4 option places four minor tick marks between each major tick mark on the vertical axis. The HREF= option draws a horizontal reference line at January 1, 1986, the date the mandatory seatbelt law took effect, and the LH= option specifies the line type.
With the introduction of ODS Graphics, the user need only turn on the graphics feature to have several standard graphics displayed. The statement ODS GRAPHICS ON; needs to be specified to enable this feature. In Table 1.1, you can see an overview of the different graphs that are produced from the different ARIMA statements. More information about the ODS graphics in PROC ARIMA can be found in the SAS/ETS User's Guide, Version 9.2.
Associated Statement |
Plot Description |
FORECAST |
Forecast Plot |
ESTIMATE |
Residual Autocorrelation Plot |
ESTIMATE |
Residual Inverse Autocorrelation Plot |
ESTIMATE |
Residual Partial Autocorrelation Plot |
ESTIMATE |
Residual White Noise Probability Plot |
ESTIMATE |
Residual Histogram |
ESTIMATE |
Residual Normal Q-Q Plot |
ESTIMATE |
Residual Partial Autocorrelation Plot |
IDENTIFY |
Series Autocorrelation Plot |
IDENTIFY |
Series Inverse Autocorrelation Plot |
IDENTIFY |
Series Partial Autocorrelation Plot |
IDENTIFY |
Trend Analysis Plot |
IDENTIFY |
Cross Correlation Plot |
For better control of graphics, you can also specify global plot option ONLY in the PLOTS= option in the PROC ARIMA statement. This suppresses generation of default plots and produces plots specified in the subsequent FORECAST or any other plot options.
For example, specific plot requests are given by specifying a statement as follows:
PLOTS(ONLY)=(SERIES(CORR CROSSCORR) RESIDUAL(NORMAL SMOOTH))
The SERIES(CORR CROSSCORR) option produces a panel of plots that are useful for the trend and correlation analysis of the series and cross-correlation plots respectively. The RESIDUAL(NORMAL SMOOTH) option produces the histogram and Q-Q plot with the NORMAL option and a scatter plot overlaid with a smooth fit with the SMOOTH option.
You can suppress the generation of all plots by using the PLOTS=NONE option. To produce all plots relevant for a particular analysis, use the PLOTS=ALL option. For more details about the various options available with ODS graphics, see SAS/ETS User's Guide, Version 9.2.
You will need to turn on the ODS graphics as shown below. The following code produces the ODS Forecast Plot in Figure 1.3. The PLOTS(ONLY)= FORECAST(FORECAST) option produces a plot that shows the one-step ahead forecasts as well as the multi-step ahead forecasts.
ods graphics on; proc arima data=drivers plots(only)=(forecast(forecast)); i var=injuries crosscorr=beltlaw; e input=beltlaw p=(1)(2 12); f lead=12 out=fore2 id=date interval=month; run; quit;Figure 1.3 Forecast Plot Produced with ODS Graphics
From the graphs, it appears that the passage of the seatbelt law caused a significant decrease in the number of road casualties.
Harvey, A.C. (1989), Forecasting, Structural Time Series Models and the Kalman Filter, Cambridge: Cambridge University Press.
SAS Institute Inc. (1996), Forecasting Examples for Business and Economics Using the SAS System, Cary, NC: SAS Institute Inc.
SAS Institute Inc. (1993), SAS/ETS User’s Guide, Version 6, Second Edition, Cary, NC: SAS Institute Inc.
SAS Institute Inc. (2008), SAS/ETS User’s Guide, Version 9.2, Second Edition, Cary, NC: SAS Institute Inc.
SAS Institute Inc. (1990), SAS/GRAPH Software: Reference, Version 6, First Edition, Volume 2, Cary, NC: SAS Institute Inc.
SAS Institute Inc. (2004), SAS/GRAPH Software: Reference, Version 9, Cary, NC: SAS Institute Inc.
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
data drivers;
format date monyy.;
input date:monyy5. injuries @@;
beltlaw = (date ge '01jan83'd);
datalines;
jan80 1665 feb80 1361 mar80 1506 apr80 1360
may80 1453 jun80 1522 jul80 1460 aug80 1552
sep80 1548 oct80 1827 nov80 1737 dec80 1941
jan81 1474 feb81 1458 mar81 1542 apr81 1404
may81 1522 jun81 1385 jul81 1641 aug81 1510
sep81 1681 oct81 1938 nov81 1868 dec81 1726
jan82 1456 feb82 1445 mar82 1456 apr82 1365
may82 1487 jun82 1558 jul82 1488 aug82 1684
sep82 1594 oct82 1850 nov82 1998 dec82 2079
jan83 1494 feb83 1057 mar83 1218 apr83 1168
may83 1236 jun83 1076 jul83 1174 aug83 1139
sep83 1427 oct83 1487 nov83 1483 dec83 1513
jan84 1357 feb84 1165 mar84 1282 apr84 1110
may84 1297 jun84 1185 jul84 1222 aug84 1284
sep84 1444 oct84 1575 nov84 1737 dec84 1763
jan85 . feb85 . mar85 . apr85 .
may85 . jun85 . jul85 . aug85 .
sep85 . oct85 . nov85 . dec85 .
;
run;
proc gplot data=drivers;
plot injuries*date=1;
symbol1 v=star c=blue;
title "Time Series Plot";
run;
quit;
title;
proc arima data=drivers;
i var=injuries crosscorr=beltlaw noprint;
e input=beltlaw p=(1)(2 12);
f lead=12 out=fore2 id=date interval=month;
run;
quit;
goptions cback=white ctitle=bl ctext=bl ftitle=centx
ftext=centx reset=(axis symbol);
proc gplot data=fore2;
format date year4.;
plot injuries*date=1
forecast*date=2
l95*date =3
u95*date =3 / overlay
haxis=axis1
vaxis=axis2
vminor=4
href='01jan83'd
lh=2;
title 'Driver Casualties Data';
title2 'Monthly Totals';
axis1 offset=(1 cm) label=('Year')
order=('01jan80'd to '01jan86'd by year);
axis2 label=(angle=90 'Casualties')
order=(750 to 2250 by 500);
symbol1 i=join l=1 c=red;
symbol2 h=2 pct v=star c=blue;
symbol3 l=20 i=join c=green;
footnote1 c=r f=centx ' --- Actual'
c=b f=centx ' * Forecast'
c=g f=centx ' --- U95/L95';
run;
quit;
title;
footnote;
ods graphics on;
proc arima data=drivers plots(only)=(forecast(forecast));
i var=injuries crosscorr=beltlaw;
e input=beltlaw p=(1)(2 12);
f lead=12 out=fore2 id=date interval=month;
run;
quit;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Type: | Sample |
Date Modified: | 2017-07-31 11:16:08 |
Date Created: | 2017-07-31 10:57:34 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | SAS/ETS | z/OS | ||
z/OS 64-bit | ||||
OpenVMS VAX | ||||
Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
Microsoft Windows XP 64-bit Edition | ||||
Microsoft® Windows® for x64 | ||||
OS/2 | ||||
Microsoft Windows 8 Enterprise 32-bit | ||||
Microsoft Windows 8 Enterprise x64 | ||||
Microsoft Windows 8 Pro 32-bit | ||||
Microsoft Windows 8 Pro x64 | ||||
Microsoft Windows 8.1 Enterprise 32-bit | ||||
Microsoft Windows 8.1 Enterprise x64 | ||||
Microsoft Windows 8.1 Pro 32-bit | ||||
Microsoft Windows 8.1 Pro x64 | ||||
Microsoft Windows 10 | ||||
Microsoft Windows 95/98 | ||||
Microsoft Windows 2000 Advanced Server | ||||
Microsoft Windows 2000 Datacenter Server | ||||
Microsoft Windows 2000 Server | ||||
Microsoft Windows 2000 Professional | ||||
Microsoft Windows NT Workstation | ||||
Microsoft Windows Server 2003 Datacenter Edition | ||||
Microsoft Windows Server 2003 Enterprise Edition | ||||
Microsoft Windows Server 2003 Standard Edition | ||||
Microsoft Windows Server 2003 for x64 | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows Server 2008 R2 | ||||
Microsoft Windows Server 2008 for x64 | ||||
Microsoft Windows Server 2012 Datacenter | ||||
Microsoft Windows Server 2012 R2 Datacenter | ||||
Microsoft Windows Server 2012 R2 Std | ||||
Microsoft Windows Server 2012 Std | ||||
Microsoft Windows XP Professional | ||||
Windows 7 Enterprise 32 bit | ||||
Windows 7 Enterprise x64 | ||||
Windows 7 Home Premium 32 bit | ||||
Windows 7 Home Premium x64 | ||||
Windows 7 Professional 32 bit | ||||
Windows 7 Professional x64 | ||||
Windows 7 Ultimate 32 bit | ||||
Windows 7 Ultimate x64 | ||||
Windows Millennium Edition (Me) | ||||
Windows Vista | ||||
Windows Vista for x64 | ||||
64-bit Enabled AIX | ||||
64-bit Enabled HP-UX | ||||
64-bit Enabled Solaris | ||||
ABI+ for Intel Architecture | ||||
AIX | ||||
HP-UX | ||||
HP-UX IPF | ||||
IRIX | ||||
Linux | ||||
Linux for x64 | ||||
Linux on Itanium | ||||
OpenVMS Alpha | ||||
OpenVMS on HP Integrity | ||||
Solaris | ||||
Solaris for x64 | ||||
Tru64 UNIX |