10-12-2013 07:02 PM
I learned that the LAG function creates a queue and populates it with a value when called. In the following example, the line "a=Lag(Value);" makes sure that LAG is called for every observation, so the queue should be well populated with the values of variable "Value".
Why is it then that when "b=Lag(Value);" is called for the first time in the second iteration ("IF _n_>=2...") no value is given to variable "b"?
Is it right to assume that there is one queue with values of variable "Value" for variable "a" and another one is initiated when "b=Lag(Value);" is called for variable b?
Input Value :$5.;
If _n_>=2 Then b=Lag(Value);
10-12-2013 08:16 PM
This Tech Support note illustrates the correct way to use the LAG function. 24665 - Use the LAG function to conditionally carry information down a data set
The Full code tab in the note shows both the correct and incorrect to call the LAG function.
Need further help from the community? Please ask a new question.