BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
matthew_m
Calcite | Level 5

I'm using phreg for the first time, and don't quite understand how it works. I'm fairly familiar with other procs (glm, etc), but phreg seems finicky. Here's my code:

data survival;
	input ID virus sex surv_days;
	label virus='0=Ctrl, 1=Virus' sex='0=M,1=F' surv_days='survival';
	datalines;
4264	1	1	3
4265	1	0	15
4269	0	0	15
4270	1	0	15
4272	0	1	15
4283	1	0	15
4284	0	1	15
4286	1	1	10
4288	0	1	5
4290	0	0	15
4293	1	1	7
4294	0	1	4
4296	1	1	4
4297	0	1	15
4299	1	0	8
4303	1	1	7
4304	0	1	15
4308	1	1	5
4310	0	0	15
4314	1	0	15
4316	0	0	15
4320	0	1	15
4325	0	0	15
4329	0	1	15
;
run;

data regimes;
	Virus=0;
	output;
	Virus=1;
	output;
	Sex=0;
	output;
	Sex=1;
	output;
run;

proc phreg data=survival plot(overlay)=survival;
	model surv_days=sex|virus;
	baseline covariates=regimes out=_null_;
	ods output ParameterEstimates=surv;
run;

From this, I have some questions:

1) my plot is only displaying 2 survival functions, labeled covariates 3 and 4. What happened to covariates 1 and 2?

2) why are my hazard ratios not displayed?

3) for my interaction (sex x virus), how do I determine which comparisons are significantly different? In proc glm, etc, I have used lsmeans / diff. That doesn't seem to work here.

 

I feel like I'm doing something fundamentally wrong here. So any advice is greatly appreciated. Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Please remember to check your log. Your code generates the following notes:

 

NOTE: Hazard ratios that cannot be conveniently calculated or displayed are set to missing in the ParameterEstimates table. Use the HAZARDRATIO statement to compute the needed hazard ratios.
NOTE: Row 1 in the COVARIATES= data set has invalid covariate values.
NOTE: Row 2 in the COVARIATES= data set has invalid covariate values.

 

For the COVARIATES data set, it needs to include values for all parameters, not just the one of interest. Ie SEX=0 and what about the VIRUS value? You do have to provide a value or level for that otherwise it won't work. Since you have two variables with two levels each, you have four baseline possibilities. 

 

You can create the REGIMES data set as below and get the values you need.

 

For the HazardRatio, add the HazardRatio statement as indicated by the log. You also should include CLASS statements to identify your categorical variables as such. Then SAS will treat it as categorical and things make more sense.

 

Modified code:

 

data regimes;
    do virus=0 to 1;
        do sex=0 to 1;
            output;
        end;
    end;
run;

proc phreg data=survival plot(overlay)=survival;
    class virus sex;
	model surv_days=sex|virus;
	baseline covariates=regimes out=_null_;
	ods output ParameterEstimates=surv;
    hazardratio sex /at (virus='0');
    hazardratio sex /at (virus='1');
    hazardratio virus /at (sex='1');
    hazardratio virus /at (sex='0');
run;

 

 


@matthew_m wrote:

I'm using phreg for the first time, and don't quite understand how it works. I'm fairly familiar with other procs (glm, etc), but phreg seems finicky. Here's my code:

data survival;
	input ID virus sex surv_days;
	label virus='0=Ctrl, 1=Virus' sex='0=M,1=F' surv_days='survival';
	datalines;
4264	1	1	3
4265	1	0	15
4269	0	0	15
4270	1	0	15
4272	0	1	15
4283	1	0	15
4284	0	1	15
4286	1	1	10
4288	0	1	5
4290	0	0	15
4293	1	1	7
4294	0	1	4
4296	1	1	4
4297	0	1	15
4299	1	0	8
4303	1	1	7
4304	0	1	15
4308	1	1	5
4310	0	0	15
4314	1	0	15
4316	0	0	15
4320	0	1	15
4325	0	0	15
4329	0	1	15
;
run;

data regimes;
	Virus=0;
	output;
	Virus=1;
	output;
	Sex=0;
	output;
	Sex=1;
	output;
run;

proc phreg data=survival plot(overlay)=survival;
	model surv_days=sex|virus;
	baseline covariates=regimes out=_null_;
	ods output ParameterEstimates=surv;
run;

From this, I have some questions:

1) my plot is only displaying 2 survival functions, labeled covariates 3 and 4. What happened to covariates 1 and 2?

2) why are my hazard ratios not displayed?

3) for my interaction (sex x virus), how do I determine which comparisons are significantly different? In proc glm, etc, I have used lsmeans / diff. That doesn't seem to work here.

 

I feel like I'm doing something fundamentally wrong here. So any advice is greatly appreciated. Thanks.


 

View solution in original post

5 REPLIES 5
Reeza
Super User

Please remember to check your log. Your code generates the following notes:

 

NOTE: Hazard ratios that cannot be conveniently calculated or displayed are set to missing in the ParameterEstimates table. Use the HAZARDRATIO statement to compute the needed hazard ratios.
NOTE: Row 1 in the COVARIATES= data set has invalid covariate values.
NOTE: Row 2 in the COVARIATES= data set has invalid covariate values.

 

For the COVARIATES data set, it needs to include values for all parameters, not just the one of interest. Ie SEX=0 and what about the VIRUS value? You do have to provide a value or level for that otherwise it won't work. Since you have two variables with two levels each, you have four baseline possibilities. 

 

You can create the REGIMES data set as below and get the values you need.

 

For the HazardRatio, add the HazardRatio statement as indicated by the log. You also should include CLASS statements to identify your categorical variables as such. Then SAS will treat it as categorical and things make more sense.

 

Modified code:

 

data regimes;
    do virus=0 to 1;
        do sex=0 to 1;
            output;
        end;
    end;
run;

proc phreg data=survival plot(overlay)=survival;
    class virus sex;
	model surv_days=sex|virus;
	baseline covariates=regimes out=_null_;
	ods output ParameterEstimates=surv;
    hazardratio sex /at (virus='0');
    hazardratio sex /at (virus='1');
    hazardratio virus /at (sex='1');
    hazardratio virus /at (sex='0');
run;

 

 


@matthew_m wrote:

I'm using phreg for the first time, and don't quite understand how it works. I'm fairly familiar with other procs (glm, etc), but phreg seems finicky. Here's my code:

data survival;
	input ID virus sex surv_days;
	label virus='0=Ctrl, 1=Virus' sex='0=M,1=F' surv_days='survival';
	datalines;
4264	1	1	3
4265	1	0	15
4269	0	0	15
4270	1	0	15
4272	0	1	15
4283	1	0	15
4284	0	1	15
4286	1	1	10
4288	0	1	5
4290	0	0	15
4293	1	1	7
4294	0	1	4
4296	1	1	4
4297	0	1	15
4299	1	0	8
4303	1	1	7
4304	0	1	15
4308	1	1	5
4310	0	0	15
4314	1	0	15
4316	0	0	15
4320	0	1	15
4325	0	0	15
4329	0	1	15
;
run;

data regimes;
	Virus=0;
	output;
	Virus=1;
	output;
	Sex=0;
	output;
	Sex=1;
	output;
run;

proc phreg data=survival plot(overlay)=survival;
	model surv_days=sex|virus;
	baseline covariates=regimes out=_null_;
	ods output ParameterEstimates=surv;
run;

From this, I have some questions:

1) my plot is only displaying 2 survival functions, labeled covariates 3 and 4. What happened to covariates 1 and 2?

2) why are my hazard ratios not displayed?

3) for my interaction (sex x virus), how do I determine which comparisons are significantly different? In proc glm, etc, I have used lsmeans / diff. That doesn't seem to work here.

 

I feel like I'm doing something fundamentally wrong here. So any advice is greatly appreciated. Thanks.


 

Reeza
Super User

Please remember to check your log. Your code generates the following notes:

 

NOTE: Hazard ratios that cannot be conveniently calculated or displayed are set to missing in the ParameterEstimates table. Use the HAZARDRATIO statement to compute the needed hazard ratios.
NOTE: Row 1 in the COVARIATES= data set has invalid covariate values.
NOTE: Row 2 in the COVARIATES= data set has invalid covariate values.

 

For the COVARIATES data set, it needs to include values for all parameters, not just the one of interest. Ie SEX=0 and what about the VIRUS value? You do have to provide a value or level for that otherwise it won't work. Since you have two variables with two levels each, you have four baseline possibilities. 

 

You can create the REGIMES data set as below and get the values you need.

 

For the HazardRatio, add the HazardRatio statement as indicated by the log. You also should include CLASS statements to identify your categorical variables as such. Then SAS will treat it as categorical and things make more sense.

 

Modified code:

 

data regimes;
    do virus=0 to 1;
        do sex=0 to 1;
            output;
        end;
    end;
run;

proc phreg data=survival plot(overlay)=survival;
    class virus sex;
	model surv_days=sex|virus;
	baseline covariates=regimes out=_null_;
	ods output ParameterEstimates=surv;
    hazardratio sex /at (virus='0');
    hazardratio sex /at (virus='1');
    hazardratio virus /at (sex='1');
    hazardratio virus /at (sex='0');
run;

 

 


@matthew_m wrote:

I'm using phreg for the first time, and don't quite understand how it works. I'm fairly familiar with other procs (glm, etc), but phreg seems finicky. Here's my code:

data survival;
	input ID virus sex surv_days;
	label virus='0=Ctrl, 1=Virus' sex='0=M,1=F' surv_days='survival';
	datalines;
4264	1	1	3
4265	1	0	15
4269	0	0	15
4270	1	0	15
4272	0	1	15
4283	1	0	15
4284	0	1	15
4286	1	1	10
4288	0	1	5
4290	0	0	15
4293	1	1	7
4294	0	1	4
4296	1	1	4
4297	0	1	15
4299	1	0	8
4303	1	1	7
4304	0	1	15
4308	1	1	5
4310	0	0	15
4314	1	0	15
4316	0	0	15
4320	0	1	15
4325	0	0	15
4329	0	1	15
;
run;

data regimes;
	Virus=0;
	output;
	Virus=1;
	output;
	Sex=0;
	output;
	Sex=1;
	output;
run;

proc phreg data=survival plot(overlay)=survival;
	model surv_days=sex|virus;
	baseline covariates=regimes out=_null_;
	ods output ParameterEstimates=surv;
run;

From this, I have some questions:

1) my plot is only displaying 2 survival functions, labeled covariates 3 and 4. What happened to covariates 1 and 2?

2) why are my hazard ratios not displayed?

3) for my interaction (sex x virus), how do I determine which comparisons are significantly different? In proc glm, etc, I have used lsmeans / diff. That doesn't seem to work here.

 

I feel like I'm doing something fundamentally wrong here. So any advice is greatly appreciated. Thanks.


 

matthew_m
Calcite | Level 5

This is incredibly helpful! I was indeed doing something fundamentally wrong! No wonder I couldn't get those hazard ratios to calculate when I tried...

 

You've solved issues 1 and 2, but what about issue 3? I hate to ask for more help on this, considering the detailed response you already provided, but do you have any thoughts on identifying which comparisons differ in the sex*virus interaction? You don't necessarily need to write the code for me, just point me in the right direction. Thanks ahead of time!

Reeza
Super User

Look at the HazardRatios and the CI for the HR to answer #3. 

 


@matthew_m wrote:

This is incredibly helpful! I was indeed doing something fundamentally wrong! No wonder I couldn't get those hazard ratios to calculate when I tried...

 

You've solved issues 1 and 2, but what about issue 3? I hate to ask for more help on this, considering the detailed response you already provided, but do you have any thoughts on identifying which comparisons differ in the sex*virus interaction? You don't necessarily need to write the code for me, just point me in the right direction. Thanks ahead of time!


 

matthew_m
Calcite | Level 5

Ah! I see! I was so focused on the p value, that I completely overlooked the confidence limits. Thanks! You're a life-saver!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 2746 views
  • 0 likes
  • 2 in conversation