pharmasug logo

  • Home
  • Conference Schedule
  • Conference Seminars
  • Registration
  • Conference Papers
  • Exhibitors & Sponsors
  • Important Dates
  • Remository
  • PharmaSUG 2010
  • PharmaSUG 2010
  • PharmaSUG 2010
  • PharmaSUG 2010
  • PharmaSUG 2010
  • PharmaSUG 2010
  • PharmaSUG 2010
  • PharmaSUG 2010
  • PharmaSUG 2010
Looking forward and backward in the same data step PDF Print E-mail
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;



 

Menu

Upcoming Conference
Tips and Techniques
Newsletters
Industry Links
SAS Press Releases (Books)
FAQ
Executive Committee
 
Privacy Policy
About PharmaSUG

Copyright © 2004-2009 The Pharmaceutical Industry SAS® Users Group

SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration.