Help using Base SAS procedures

reverse of lag function?

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

reverse of lag function?

How can I go from this:

a1 b1 c1    z1

a2 b2 c2    z2

a3 b3 c3    z3

to this:

a1 b1 c1    z2

a2 b2 c2    z3

a3 b3 c3    z4

without lagging the a, b, and c variables? Is there a way to pull back the z variable?

The reason I'd like to avoid this is because I've got many variables of the a, b, and c type that I don't want to mess with / rename, and only one like the z variable that I'd like to move back to the preceding observation.

Thanks.


Accepted Solutions
Solution
‎01-23-2012 07:11 AM
PROC Star
Posts: 7,357

reverse of lag function?

One possibility is the look ahead, look back method as described at:

It is based on the look ahead look back method that is described at:http://www.sascommunity.org/wiki/Look-Ahead_and_Look-Back

However, you would only need to apply the look ahead part, as you appear to want to apply the next z value to each current record.

View solution in original post


All Replies
Solution
‎01-23-2012 07:11 AM
PROC Star
Posts: 7,357

reverse of lag function?

One possibility is the look ahead, look back method as described at:

It is based on the look ahead look back method that is described at:http://www.sascommunity.org/wiki/Look-Ahead_and_Look-Back

However, you would only need to apply the look ahead part, as you appear to want to apply the next z value to each current record.

New Contributor
Posts: 4

Re: reverse of lag function?

Thanks, got it!!

Occasional Contributor
Posts: 8

reverse of lag function?

Try this:

data b;

   merge a(keep=a b c) a(keep=z firstobs=2);

run;

PROC Star
Posts: 7,357

reverse of lag function?

Alfredo, That is basically the look ahead method.  It is easier, though, to simply drop the look ahead variable from the first file, rather than explicitly keep all of the others.  And if you are going to use merge rather than 2 set statements, you have to insure you have the correct setting for the mergenoby option.

Respected Advisor
Posts: 3,777

Re: reverse of lag function?

proc expand data=sashelp.class out=lead;

   convert weight=leadWeight  / method=none transformout=(lead 1);

   run;

proc print;

   run;

Frequent Contributor
Posts: 129

Re: reverse of lag function?

But you need ETS for proc expand:-(

Respected Advisor
Posts: 3,777

Re: reverse of lag function?

Yes they should move it to BASE.  Jim?

PROC Star
Posts: 7,357

Re: reverse of lag function?

And, if he is listening, AF should be moved there as well.

New Contributor
Posts: 4

Re: reverse of lag function?

Thanks for the help guys. I'll give these a try and get back to you.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 13650 views
  • 0 likes
  • 5 in conversation