BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jaxonmills
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

9 REPLIES 9
art297
Opal | Level 21

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.

jaxonmills
Calcite | Level 5

Thanks, got it!!

Alfredo
Fluorite | Level 6

Try this:

data b;

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

run;

art297
Opal | Level 21

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.

data_null__
Jade | Level 19

proc expand data=sashelp.class out=lead;

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

   run;

proc print;

   run;

LarryWorley
Fluorite | Level 6

But you need ETS for proc expand:-(

data_null__
Jade | Level 19

Yes they should move it to BASE.  Jim?

art297
Opal | Level 21

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

jaxonmills
Calcite | Level 5

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 9 replies
  • 35179 views
  • 2 likes
  • 5 in conversation