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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.