BookmarkSubscribeRSS Feed
aidant01
Fluorite | Level 6

Hi everyone, 

 

I'm getting:

 

var1var2var3
A1/1/14 
A1/2/141/1/14
A1/3/141/2/14
A1/4/141/3/14
A1/5/141/4/14
A1/6/141/5/14
A1/7/141/6/14
A1/8/141/7/14
A1/9/141/8/14
A1/10/141/9/14
A1/11/141/10/14
A1/12/141/11/14

 

 

I want:

 

var1var2var3
A1/1/141/2/14
A1/2/141/3/14
A1/3/141/4/14
A1/4/141/5/14
A1/5/141/6/14
A1/6/141/7/14
A1/7/141/8/14
A1/8/141/9/14
A1/9/141/10/14
A1/10/141/11/14
A1/11/141/12/14
A1/12/14 

 

I'm using the following code:

 

data datawant;

set dataraw;

var3=lag(var2);

run;

 

Thanks!!!

1 REPLY 1
PeterClemmensen
Tourmaline | Level 20

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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 728 views
  • 0 likes
  • 2 in conversation