How does SAS save the value from the previous line without a save statement?

I am working on this example which explains how to fit the standard Cox model with proc mcmc in SAS 9.3 .

For the first row in the data ( ind=1 ), S=exp(bZ) calculated along with other values. It is important to note that S is a new variable built from the columns of the original dataset.

For the second row ( 1 < in < &N ), S increases: S = S + exp(bZ) .

Question: How does SAS save the S value from the previous line? I would expect a retain statement or something equivalent ...


Relevant piece of code:

 if ind = 1 then do; /* first observation */ S = exp(bZ); l = vstatus * bZ; v = vstatus; end; else if (1 < ind < &N) then do; if (lag1(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; 
+4
source share
2 answers

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.

+2
source

I'm sorry this is not an answer, just pay attention to what is said at http://support.sas.com/documentation/cdl/en/statug/63962/HTML/default/viewer.htm#statug_mcmc_sect017.htm

Most of the programming instructions that can be used in the DATA step can also be used in the PROC MCMC.

and

For the most part, SAS programming instructions work the same way as they are executed in the DATA step, as described in the SAS Language Reference: Concepts. However, there are several differences ...

So my impression is that the syntax inside the BEGINCNST and ENDCNST almost the same as in the datastep, but some of the inner workings are different from each other, which probably relates to storing the calculated values ​​(?). This probably does not work the same as in datastep PDV (program data vector).

+2
source

Source: https://habr.com/ru/post/1437333/


All Articles