Sample 24666: Creating the equivalent of the LEAD function by comparing the value of a variable to its value in the next observation
Within the same data set, look ahead from a variable value in one observation to return the value of the same variable in the observation that immediately follows it.
Note:
This sample comes from "Combining and Modifying SAS Data Sets: Examples", Example 5.6.
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.
/* Create sample data */
data one;
input x y;
datalines;
5 1
5 2
10 1
2 1
2 2
19 1
;
/* Create TWO by merging ONE with itself. Begin reading the second */
/* reference to data set ONE with the second observation. RENAME= */
/* renames X so that the look-ahead value doesn't overwrite the current */
/* value of X in the program data vector. */
data two;
merge one one(firstobs=2 rename=(x=nextx) keep=x);
if x=nextx then match='YES';
else match='NO';
run;
proc print data=TWO;
run;
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.
Obs x y nextx match
1 5 1 5 YES
2 5 2 10 NO
3 10 1 2 NO
4 2 1 2 YES
5 2 2 19 NO
6 19 1 . NO
Within the same data set, look ahead from a variable value in one observation to return the value of the same variable in the observation that immediately follows it.
Type: | Sample |
Topic: | SAS Reference ==> DATA Step SAS Reference ==> Functions ==> Special
|
Date Modified: | 2020-04-20 12:18:42 |
Date Created: | 2004-09-30 14:09:02 |
Operating System and Release Information
SAS System | Base SAS | All | n/a | n/a |