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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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