I am trying to compute a column in SAS that has a dependency on itself. For example, I have the following list of initial values
ID Var_X Var_Y Var_Z 1 2 3 . 2 . 2 . 3 . . . 4 . . . 5 . . . 6 . . . 7 . . .
I need to fill in the blanks. The formulas are as follows:
Var_Z = 0.1 + 4*Var_x + 5*Var_Y Var_X = lag1(Var_Z) Var_Y = lag2(Var_Z)
As we can see, the values โโof Var_X, Var_Y and Var_Z are interdependent. Thus, the calculation must follow a certain order.
First we compute when ID = 1, Var_Z = 0.1 + 4*2 + 5*3 = 23.1 Next, when ID = 2, Var_X = lag1(Var_Z) = 23.1
Var_Y does not need to be calculated with ID = 2, since here we already have the initial value. So we have
ID Var_X Var_Y Var_Z 1 2 3 23.1 2 23.1 2 102.5 (= 0.1 + 4*23.1 +5*2) 3 . . . 4 . . . 5 . . . 6 . . . 7 . . .
We continue to repeat this procedure until all values โโare calculated.
Is there any way SAS can handle this? I tried the DO loop, but I think I didn't program it very well. It just stops after ID = 2.
I'm new to SAS, so I don't know if there is a way that SAS can handle this easily. They will be waiting for your suggestions.
source share