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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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