FOCUS AREAS

SAS/ETS Web Examples

Plotting Time Series Data


Contents | Back to Example


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;