This is a very robust way to access and combine previous as well as consecutive observations in a data step. Here is a complementary approach combining lag() and lead() into single hop(): Hopping for the best - calculations across SAS dataset observations.