This is the lag1() function, which stores the values, but be careful!
The lag() function will remember the value from the previous time it was executed, not the previous line! Since your delay function is only executed when the first if condition if not true, then it can be difficult to debug problems arising from this.
I suggest changing the use of the retain statement, which is more explicit and easier to debug. If you prefer to use the lag1() function and you are having problems with the code, I suggest you move it from conditional logic so that your code looks like this:
prev_time = lag1(time); if ind = 1 then do; /* first observation */ S = exp(bZ); l = vstatus * bZ; v = vstatus; end; else if (1 < ind < &N) then do; if prev_time ne time then do; l = vstatus * bZ; l = l - v * log(S); /* correct the loglike value */ v = vstatus; /* reset v count value */ S = S + exp(bZ); end; else do; /* still a tie */ l = vstatus * bZ; S = S + exp(bZ); v = v + vstatus; /* add # of nonsensored values */ end; end;
BTW - there lag(), lag1(), lag2(), lag3(), etc.... functions that also exist.
source share