Programming the statistical procedures from SAS

Proc phreg - time-varying predictor

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

Proc phreg - time-varying predictor

Hi all!

 

I have a question about the class statement in proc phreg. I am trying to run a cox regression model with a time-varying predictor. Whenever I run the model, I get completely blank output. I think it has something to do with the class statement.

 

When I try to run the model with a time-nonvarying predictor (using only the first treatment that people received, instead of modeling treatment as time-varying), it only works if I include the predictor in the class statement. This is an example of the model with the time-nonvarying predictor:

 

Proc phreg data=outcomes;
Class treatment (ref="0");
Model Timetostatus*event1yes(0) = treatment1;
Run;

The code above does give me appropriate output. It does NOT work if I exclude the class statement.

 

However, I actually want to make treatment a time-varying predictor like below:

 

Proc phreg data=outcomes;
Model Timetostatus*event1yes(0) = treatment;
If timetostatus < regimen1_timetoend then treatment = treatment1;

Else If timetostatus > regimen2_timetostart and timetostatus <= regimen2_timetoend then treatment = treatment2;
Run;

 

When I run the model above, the output is blank, and SAS shows as if no events occurred. I have carefully checked all the variables that I have used to make treatment a time-varying predictor; they have all been calculated correctly, and there are definitely events. So I am assuming that the reason why the output is blank is that I have not put treatment in the class statement, since I had to do that in the first model. Is there a way to include a time-varying predictor in the class statement? I have tried a model including the class statement with treatment; I also tried a model with treatment1 and treatment2 in the class statement. None of those worked.

 

Any thoughts on this?


Accepted Solutions
Solution
‎06-09-2018 05:37 PM
Contributor
Posts: 23

Re: Proc phreg - time-varying predictor

Thanks, ballardw!

 

Since posting my question, I was able to figure out what was wrong. My predictor (binary:1 = on treatment, 0 = not on treatment) was coded as a character variable instead of as a numeric variable, so SAS wanted me to include it in the class statement. I just changed the predictor from a character variable to a numeric variable, and now proc phreg is giving me appropriate Cox regression output even with the time-varying predictor.

 

I just thought I would post this in case anyone else runs into the same problem in the future.

View solution in original post


All Replies
Super User
Posts: 13,583

Re: Proc phreg - time-varying predictor

This appears to be data content related. Can you share a subset of your data that demonstrates the behavior.

 

 

Doesn't work is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

 

Solution
‎06-09-2018 05:37 PM
Contributor
Posts: 23

Re: Proc phreg - time-varying predictor

Thanks, ballardw!

 

Since posting my question, I was able to figure out what was wrong. My predictor (binary:1 = on treatment, 0 = not on treatment) was coded as a character variable instead of as a numeric variable, so SAS wanted me to include it in the class statement. I just changed the predictor from a character variable to a numeric variable, and now proc phreg is giving me appropriate Cox regression output even with the time-varying predictor.

 

I just thought I would post this in case anyone else runs into the same problem in the future.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 175 views
  • 1 like
  • 2 in conversation