SUPPORT / SAMPLES & SAS NOTES
 

Support

Sample 36199: Creating the equivalent of a LEAD function by using the POINT= option in the SET statement

DetailsCodeOutputAboutRate It

The concept of a LEAD function infers the ability to look ahead to a subsequent observation in a data set. This functionality can be obtained by using the SET statement's POINT= variable option.

By assigning an observation number to the numeric variable specified with the option, and then using the option in a second SET statement, a subsequent observation can be accessed (read into the program data vector, or PDV) in addition to the current observation.

Because a variable name can exist only once in the PDV, the second SET statement would ordinarily result in the value of the variables from the first SET statement being overwritten. To avoid this behavior, the KEEP= and RENAME= data set options should be used with the second SET statement to read in only the pertinent variables and to give them a new name.

When the POINT= option is used with a SET statement, and that specific SET statement is the only statement that reads an observation from a data set, then a STOP statement is required. The STOP statement lets the SAS® program know when to terminate the DATA step. In this sample, the initial SET statement (without the POINT= option) reads every observation sequentially. As such, SAS will terminate the DATA step when all the observations have been read via that SET statement.

See also SAS Note 24666, "Creating the equivalent of the LEAD function by comparing the value of a variable to its value in the next observation."




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.