Previous Page | Next Page

Working with Time Series Data

Leading Series

Although the SAS System does not provide a function to look ahead at the "next" value of a series, there are a couple of ways to perform this task.

The most direct way to compute leads is to use the EXPAND procedure. For example:

proc expand data=uscpi out=uscpi method=none;
   id date;
   convert cpi=cpilead1 / transform=( lead 1 );
   convert cpi=cpilead2 / transform=( lead 2 );
run;

Another way to compute lead series in SAS software is by lagging the time ID variable, renaming the series, and merging the result data set back with the original data set.

For example, the following statements add the variable CPILEAD to the USCPI data set. The variable CPILEAD contains the value of CPI in the following month. (The value of CPILEAD is missing for the last observation, of course.)

data temp;
   set uscpi;
   keep date cpi;
   rename cpi = cpilead;
   date = lag( date );
   if date ^= .;
run;

data uscpi;
   merge uscpi temp;
   by date;
run;

To compute leads at different lead lengths, you must create one temporary data set for each lead length. For example, the following statements compute CPILEAD1 and CPILEAD2, which contain leads of CPI for 1 and 2 periods, respectively:

data temp1(rename=(cpi=cpilead1))
     temp2(rename=(cpi=cpilead2));
   set uscpi;
   keep date cpi;
   date = lag( date );
   if date ^= . then output temp1;
   date = lag( date );
   if date ^= . then output temp2;
run;

data uscpi;
   merge uscpi temp1 temp2;
   by date;
run;
Previous Page | Next Page | Top of Page