08-13-2016 06:33 AM
I would be glad, if you could help me with the following problem.
What I am aiming at implementing is the following:
In the first row, I calculate a specific variable, e.g., y = x*a;
Said y shall be carried forward to the second row a play the role as the new x. The same calculation is performed, i.e., y=x*a, whereby the x for the second row is the y from the first row;
That is the input
I am considering.
It would be kind, if you could give me a hint, on how to I tackle this kind of problem?
As SAS "work" row to row (as I have understood), it should give a "trick"?
Otherwise, for each step, I would have to create an index, separate the y, merge the y to the next observation, replace x with the carried-forward-y and calculate once again.
This would result in a huge amount of data steps.
data have; input x a; datalines; 1 2 . 2 . 2 . 2 . 2 . 2 . 2 . 2 . 2 . 2 ; run;
08-13-2016 07:56 AM
Here is a way by data step. Replace x by everytime before the next iteration like:
data have; a = 2; do i = 1 to 10; if i = 1 then x = 1; y = x * a; output; x = y; end; drop i; run; proc print; run;
Hope this is an acceptable solution to you.
08-14-2016 09:04 AM
this is enormous.
I really had allready implemented it via a %macro %Do Loop.
The amount of time if do save is astonishing.
Thank you so much for this - I need this very procedure "over an over" so this really changes the game.
As I do have to implement it for more than one variable, would you mind considering if I have transferred it correctly to a setting more closely to the actual one?
data want; set have; retain x_end y_end z_end; if _n_ ne 1 then x=x_end; if _n_ ne 1 then y=y_end; if _n_ ne 1 then z=z_end; x_end = intercept1 + a*x + b*y + c*z ; y_end = intercept2 + d*x + e*y + f*z ; z_end = intercept3 + g*x + h*y + i*z ; run;
So, former y is now "x_end";
Especially, the three ifs are a concern of mine - could I achieve a better solution?
But, nonetheless, your very answer means a huge leap indeed for me.
Once again, thank you so much.
Need further help from the community? Please ask a new question.