PANEL Procedure

LAG, CLAG, SLAG, XLAG, and ZLAG Statements

  • LAG varSubscript 1(lagSubscript 1 lagSubscript 2lagSubscript upper T) …varSubscript upper N(lagSubscript 1 lagSubscript 2lagSubscript upper T) / OUT=SAS-data-set;

Generally, creating lags of variables in a panel setting is a tedious process that requires many DATA step statements. The PANEL procedure enables you to generate lags of any series without stepping through individual time series. The LAG statement is a data set generation tool. You can specify more than one LAG statement. Analyzing the generated lagged data requires a subsequent call to PROC PANEL.

The OUT= option is required. The output data set includes all variables in the input set, plus the generated lags, which are named using the convention varname_lag. The LAG statement tends to generate many missing values in the data. This can be problematic because the number of usable observations decreases with the lag length. Therefore, PROC PANEL offers several alternatives to the LAG statement. You can use the following statements in place of the LAG statement with otherwise identical syntax:

CLAG replaces missing values with the cross-sectional mean for that variable.

SLAG replaces missing values with the time mean for that variable.

XLAG replaces missing values with the overall mean for that variable.

ZLAG replaces missing values with 0 for that variable.

For all these alternative statements, missing values are replaced only if they are in the generated (lagged) series. Missing variables in the original variables remain unchanged.

Assume that data set A has been sorted by cross section and by time period within cross section and that the variables are Y, X1, X2, and X3. The following PROC PANEL statements generate a series with lags 1 and 3 of the X1 variable; lags 3, 6, and 9 of the X2 variable; and lag 2 of the X3 variable:

proc panel data=A;
   id i t;
   lag X1(1 3) X2(3 6 9) X3(2) / out=A_lag;
run;

If you want zeroing instead of missing values, then use the ZLAG statement in place of the LAG statement:

proc panel data=A;
   id i t;
   zlag X1(1 3) X2(3 6 9) X3(2) / out=A_zlag;
run;

Similarly, you can use the XLAG statement to replace missing values with overall means, the SLAG statement to replace them with time means, and the CLAG statement to replace them with cross-sectional means.

Last updated: June 19, 2025