next up previous
Next: Using S-Plus to do Up: No Title Previous: Computing for Chapter 2

Using SAS to do Time Series Plots and Plots of the Sample ACF (Autocorrelation Function).

  I have already downloaded the data into a file ``cow.dat''.

I fired up the SAS system, and a number of windows appeared on my screen. To get the data into SAS, I typed the following lines into the SAS: PROGRAM EDITOR window:

filename mydata 'cow.dat';
data cow;
infile mydata;
input temp;
run;
(Actually, there are some 5 digit numbers already numbering the lines in the PROGRAM EDITOR window which I didn't show.) I learned about this method from the ``Reading from an External File'' at the New Zealand sasintro web site. NOTE HOW ALL SAS STATEMENTS END WITH A SEMICOLON. My data set will be called ``cow'' and it will have only one variable, ``temp'' (for temperature).

I then select ``Submit'' from the Locals menu (top of the PROGRAM EDITOR window in the bar) and the statements are executed. The SAS LOG window tells me there is an error because it can't find the data file cow.dat in the directory where I am running SAS, so I move the file into that directory. I then select ``Recall Text'' from the Locals menu and all 5 lines reappear. I do the ``Submit'' again and the SAS LOG window tells me 75 records were read. My cow data set (with the temp variable) is in SAS now.

I next want to do a time series plot (or time plot) of the data. I really don't know how to do this, so I select ``Extendend Help'' from the Help menu in the PROGRAM EDITOR window and a new SAS System Help window pops up (you can fill your desktop in a hurry when you run SAS). I select ``MODELING & ANALYSIS TOOLS'' in the Help window after a little trial and error and seeing that there is an ``Econometrics & Time Series'' link from there, which I take. Then I select the ``Time Series Viewer'' link. Based on what I read there, I type ``tsview data=cow var=temp;'' in the PROGRAM EDITOR window and get an error message in the SAS LOG window. So I go to the ``Toolbox: PROGRAM EDITOR'' window (which is real skinny top to bottom) and has a little place where you type in commands and typed in ``tsview data=cow var=temp'' (no ``;'' at the end) and left mouse click on the check on the left end of this window. A funny looking error message window pops up that makes very little sense to me but I get the idea that I hadn't properly specified the ID variable in the tsview command.

So, I went back and redid the DATA step:

me mydata 'cow.dat';
data cow;
infile mydata;
input temp;
time=_N_;
run;
The SAS LOG window tells me I have a data set with 2 variables: temp and time. I go back and redo the ``tsview data=cow var=temp'' in the little Toolbox window and lo and behold a really cute little time plot of my data pops up. I want to get the plot out into some file so I somehow figure out how to use the File $\rightarrow$Print Graph menu to ``print'' the graph as a GIF file, which you see below. (I haven't been able to reproduce that.) It turns up in my directory as ``graph.gsf'' and I change it to tsplot.gsf.

I get a plot of the sample autocorrelation function either by going to the View menu or clicking the unobvious second button on the right side of the window. The autocorrelation appears (vertically) on the left side of the next picture.

(I changed the file name to acf.gsf (acf for ``autocorrelation function''), something I do to avoid having the file clobbered by the next print). I also try to File $\rightarrow$ Print Data so as to get a printout of the sample, but that seems to hang up SAS. I guess that isn't supposed to be done. Anyway, I go back and find in the Options menu a ``Correlation Probabilities'' option that allows me to get some lines on my plots indicating which correlations are significantly nonzero.

The numerical values of the sample acf appear in the SAS: OUTPUT window (along with a lot of other crap). Here is the 1st few lines:

                              The SAS System                              1
                                             15:53 Tuesday, February 2, 1999
                           Autocorrelation Plots

                                    TEMP



 LAG   N          ACOV   LACF  ACF   UACF  ACF_PRB  LPACF  PACF  UPACF

  0   75  90.923733333  0.000    1  0.000  0.0001   0.000    1   0.000
  1   74     37.324672  -.231  .41  0.231  0.0004   -.231  .41   0.231
  2   73  38.456810667  -.267  .42  0.267  0.0015   -.231  .31   0.231
  3   72  36.824682667  -.301  .41  0.301  0.0071   -.231  .21   0.231
  4   71  33.882154667  -.328  .37  0.328  0.0233   -.231  .13   0.231
  5   70      14.82016  -.350  .16  0.350  0.3520   -.231  -.2   0.231
The sample ACF appears under the column "ACF".

Getting the lagged scatterplot is even more fun. The only way I can figure out how to do it is to get a new variable in the data set which is the lagged value of temp. Back to the data step:

filename mydata 'cow.dat';
data cow;
infile mydata;
input temp;
time=_N_;
templag=lag1(temp);
run;
After submitting this, I invoked PROC PLOT to get the plot.
proc plot;
plot temp*templag;
run;
This produces a lousy line printer plot that appears in the output window. It is reproduced below.
                               The SAS System                              1
                                           12:05 Wednesday, February 3, 1999

         Plot of TEMP*TEMPLAG.  Legend: A = 1 obs, B = 2 obs, etc.

 TEMP |
      |
   96 +                   A
      |
   84 +
      |
   72 +                      B   B         B                        A
      |             A                      A
   60 +         A  A A BA  A  A  C         A
      |     AA     AABAAA  CA AA A     A  AB
   48 +      ABB  B A AB B CB   AA A    A
      |      A A  AAAAA   AA    A
   36 +
      |
      ---+--------+--------+--------+--------+--------+--------+--------+--
        36       45       54       63       72       81       90       99

                                     TEMPLAG

NOTE: 1 obs had missing values.
SAS afficianadoes probably know how to use some tool that pops up a nice window (is it Insight?) but the SAS help system was not sufficiently informative that I could figure it out. Let me know if you know how to do it.

In summary, I found this exercise to be a royal pain in the SAS. I recommend using Splus. 


next up previous
Next: Using S-Plus to do Up: No Title Previous: Computing for Chapter 2 
Dennis Cox

2/3/1999