| Looking forward and backward in the same data step |
|
|
|
|
Have you ever had to look forward and backward (lag) in the same dataset. Here is a technique to accomplish this. Richard Read Allen Peak Statistical Services www.peakstat.com data given; input PR PP PE; cards; 26117 12644 78765 26117 12644 78766 26117 12644 78767 26117 12644 79398 26117 12644 80601 26117 12644 81343 26117 12644 81503 26117 12644 83429 32640 15436 107309 32640 15436 114404 32640 15436 163072 32640 15436 166924 32640 15436 94725 32640 15436 94726 32640 15436 94727 32640 15436 94728 data LagForward; set Given; by PR PP; /*-- Forward ------------*/ _p=_n_+1; if _p<1 then next_PE=.; else if ^last.PP then set Given(keep=PE rename=(PE=next_PE)) point=_p; else next_PE=.; /*-- Lag ----------------*/ _q=_n_-1; if _q<1 then last_PE=.; else if ^first.PP then set Given(keep=PE rename=(PE=last_PE)) point=_q; else last_PE=.; run; |
|
| Last Updated ( Tuesday, 14 August 2007 ) |













