Often times SAS® programmers need to retain the value of a variable in the current observation to the next observation. The LAG function can be very helpful here. A LAGn (n=1-100) function returns the value of the nth previous execution of the function. It is easy to assume that the LAGn functions return values of the nth previous observation.
Example : Create a single lag of one variable */
d ata one; input x; lagonce=lag(x); datalines; 1 2 3 4 5 ; proc print data=one; title 'Sample1: Single lag of one variable'; run;
Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!