If the LAG function
returns a value to a character variable that has not yet been assigned
a length, by default the variable is assigned a length of 200.
The LAG functions, LAG1,
LAG2, ..., LAGn
from a queue. LAG1 can also be written as LAG. A LAGn
function stores a value in a queue and returns
a value stored previously in that queue. Each occurrence of a LAGn
function in a program generates its own queue
The queue for each occurrence
is initialized with n
missing values, where n
is the length of the queue (for example, a LAG2 queue is initialized
with two missing values). When an occurrence of LAGn
is executed, the value at the top of its queue
is removed and returned, the remaining values are shifted upwards,
and the new value of the argument is placed at the bottom of the queue.
Hence, missing values are returned for the first n
executions of each occurrence of LAGn
, after which the lagged values of the argument
begin to appear.
Storing values at the bottom
of the queue and returning values from the top of the queue occurs
only when the function is executed. An occurrence of the LAGn
function that is executed conditionally will
store and return values only from the observations for which the condition
If the argument of LAGn
is an array name, a separate queue is maintained
for each variable in the array.