Posts

Showing posts with the label Lead Function

How to read next record while working on the current record. (LEAD FUNCTION)

Even though there is no function is available in SAS to do exactly the opposite work of the LAG function (i.e: reading the next record while working on the current one), there are few things you can do to do exactly that. Here are few simple techniques which are proved to work without any problem. *SAMPLE DATASET; data test; input id age grp ; datalines ; 1 10 1 2 20 1 3 30 1 4 40 1 5 50 1 1 10 2 2 20 2 3 30 2 4 40 2 5 50 2 ; run ; *1) Using the POINT feature along with automatic variable _N_; This solution was suggested by Paul M. Dorfman ; data leads; _n_ ++ 1 ; if _n_ le n then do; set one point=_n_; leadage=age; end ; set one nobs=n; run ; *OR*; data leads; _n_ ++ _n_ lt n; set one point=_n_; leadage=age; set one nobs=n end=end; if end then leadage= . ; run ; By using the above techniques, you can jump a bit higher and even look values of two, three or any numbers of observations in advance by advancing the value of...