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.
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.
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.
Thanks, got it!!
Try this:
data b;
merge a(keep=a b c) a(keep=z firstobs=2);
run;
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.
proc expand data=sashelp.class out=lead;
convert weight=leadWeight / method=none transformout=(lead 1);
run;
proc print;
run;
But you need ETS for proc expand:-(
Yes they should move it to BASE. Jim?
And, if he is listening, AF should be moved there as well.
Thanks for the help guys. I'll give these a try and get back to you.
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!
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.