SUPPORT / SAMPLES & SAS NOTES
 

Support

Sample 24665: Use the LAG function to conditionally carry information down a data set

DetailsCodeOutputAboutRate It

It is important to understand how the LAG function works in order to achieve the desired results.

The value of the LAG function is returned to a queue. Each time the LAG function is executed, the value at the top of its queue is removed and returned, and all remaining values are shifted upward. The new value returned by the function is placed at the bottom of the queue. This process occurs only when the function is executed. A conditionally executed LAG function only stores and return a value from the observation that meets the condition. That means the LAG function returns the value from the last observation that met the conditional logic, which might not be the previous observation.

The sample code on the Full Code tab illustrates the effects of executing the LAG function conditionally.




These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.