Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8610661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:11:09+00:00 2026-06-12T04:11:09+00:00

I am working on this example which explains how to fit a standard Cox

  • 0

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

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

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

Question: How does SAS retain the value of S from the previous row? I would have expected a retain statement or something equivalent…


Relevant part of the 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;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:11:10+00:00Added an answer on June 12, 2026 at 4:11 am

    It’s the lag1() function that is retaining values but be careful!

    The lag() function will remember the value from the previous time it was executed, not the previous row! Because your lag function only gets executed when the first if condition is not true, then there may be hard to debug problems arising from this.

    I suggest changing to use a retain statement which are more explicit and easier to debug. If you do choose to keep using the lag1() function and you are having problems with the code I suggest you move it out of the conditional logic so 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’s lag(), lag1(), lag2(), lag3(), etc.... functions that also exist.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with a Google Maps example code , this : http://www.wolfpil.de/v3/drag-from-outside.html which has
UPDATE: This is the working example. First we create a class to hold weekday,
I was working through texture mapping and I found this example which I cant
I am working with this example to try and learn Sencha Touch. I have
This example working great because here containment is body http://jsfiddle.net/roXon/hMmbK/2/ when i use container
please look at this example of drop down checkbox list im working on.. http://jsfiddle.net/Yojik/VJHVK/143/
I'm trying to style a TreeView using this example and everything was working fine
I have this simple example I can't seems to get working : MERGE INTO
I'm working on a bigger project atm, but I made this simple example to
I'm currently working on a project which uses many ajax requests to access data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.