2   The LAG and DIF Functions

Introduction

Using the LAG Function to Compute Differences

Demonstrating Some Related Functions: LAG2, LAG3, and So Forth

Demonstrating the DIF Function

Introduction

When you think about looking back across observations, you either think about using retained variables or the LAG function. Retained variables allow you to access values of SAS variables from previous observations. The LAG functions (LAG, LAG2, and so forth) are more specific: they return values from previous iterations of the DATA step. One common application for a LAG function is to compare a value in the current observation to one in the previous observation. This provides you with an easy way to compute differences between observations in a SAS data ...

Get Longitudinal Data and SAS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.