Hi everyone,
I'm getting:
| var1 | var2 | var3 |
| A | 1/1/14 | |
| A | 1/2/14 | 1/1/14 |
| A | 1/3/14 | 1/2/14 |
| A | 1/4/14 | 1/3/14 |
| A | 1/5/14 | 1/4/14 |
| A | 1/6/14 | 1/5/14 |
| A | 1/7/14 | 1/6/14 |
| A | 1/8/14 | 1/7/14 |
| A | 1/9/14 | 1/8/14 |
| A | 1/10/14 | 1/9/14 |
| A | 1/11/14 | 1/10/14 |
| A | 1/12/14 | 1/11/14 |
I want:
| var1 | var2 | var3 |
| A | 1/1/14 | 1/2/14 |
| A | 1/2/14 | 1/3/14 |
| A | 1/3/14 | 1/4/14 |
| A | 1/4/14 | 1/5/14 |
| A | 1/5/14 | 1/6/14 |
| A | 1/6/14 | 1/7/14 |
| A | 1/7/14 | 1/8/14 |
| A | 1/8/14 | 1/9/14 |
| A | 1/9/14 | 1/10/14 |
| A | 1/10/14 | 1/11/14 |
| A | 1/11/14 | 1/12/14 |
| A | 1/12/14 |
I'm using the following code:
data datawant;
set dataraw;
var3=lag(var2);
run;
Thanks!!!
What you want here is not a lag. It is a lead (look ahead). Due to the construction of the data step processing, it does not support a lead function. However, you can do a workaround like this
data have;
input var1 $ var2:mmddyy10.;
format var2 mmddyy10.;
datalines;
A 1/1/14
A 1/2/14
A 1/3/14
A 1/4/14
A 1/5/14
A 1/6/14
A 1/7/14
A 1/8/14
A 1/9/14
A 1/10/14
A 1/11/14
A 1/12/14
;
data want;
merge have have(firstobs=2 keep=var2 rename=(var2=var3));
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.