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;
Navigate AI governance with SAS tools for compliance and ethical AI practices. Try SAS Ai Navigator for free for the first six months.
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.