Quantcast
Viewing all articles
Browse latest Browse all 310

LAG( ) or DO-LOOP?

I have the following data:

X Y Z
1 2 .
. 3 .
. 4 .
. 5 .
. 6 .

For the first row of data, I have:

X=1
Y=2
Z=X+Y -> 3. Z will always = X+Y. However, The 2nd row X = 1st row Z. So after computing the first Z, my dataset looks like:

X Y Z
1 2 3
3 3 .
. 4 .
. 5 .
. 6 .

Then the 2nd Z=6

X Y Z
1 2 3
3 3 6
6 4 .
. 5 .
. 6 .

....
....

this repeats. Overall, Z depends on X and Y but X depends on the previous Z. I need to find some way to do this automatically and I'm not quite sure how to tell SAS that Z=X+Y and that X=Z from the previous row.

I think I may need to either use a do-loop or use the lag() function somehow but not sure....any help would be greatly appreciated!

Thanks!

Viewing all articles
Browse latest Browse all 310

Trending Articles