Calcite | Level 5

## Plotting the log hazard/survival vs a variable

Hi,

I'm using survival data and I want to plot the log hazard of the outcome vs age (a variable in my data set) to see if the relationship between age and the log hazard is linear, but I'm not sure how to create such a plot.

For example, how would make the plot using this data set:

data kidney;
input time cens age nephrectomy @@;
cards;
9 1 50 0 6 1 55 0 21 1 45 0 15 1 52 0 8 1 62 0 17 1 62 0 12 1 53 0 104 0 61 1
9 1 41 1 56 1 51 1 35 1 61 1 52 1 41 1 68 1 31 1 77 0 71 1 84 1 71 1 8 1 51 1
36 1 61 1 72 1 51 1 36 1 41 1 48 1 31 1 26 1 41 1 108 1 31 1 5 1 41 1 108 0 52 1
26 1 52 1 14 1 62 1 115 1 52 1 52 1 42 1 5 0 25 1 18 1 42 1 36 1 52 1 9 1 62 1
10 1 43 1 9 1 53 1 18 1 43 1 6 1 43 1
;
run; proc print;

1 ACCEPTED SOLUTION

Accepted Solutions

## Re: Log hazards

Consider this SAS example using PROC LIFETEST: Example 70.3 Life-Table Estimates for Males with Angina Pectoris, which includes "and estimated hazard function are requested by the PLOTS= option".

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
13 REPLIES 13
Super User

## Re: Plotting the log hazard/survival vs a variable

Have you checked if this functionality is in PROC PHREG already? What version of SAS do you have?

What does your PROC PHREG code look like, ie how are you calculating hazard and are there other variables involved?

Hi,

I'm using survival data and I want to plot the log hazard of the outcome vs age (a variable in my data set) to see if the relationship between age and the log hazard is linear, but I'm not sure how to create such a plot.

For example, how would make the plot using this data set:

data kidney;
@input time cens age nephrectomy @@;
cards;
9 1 50 0 6 1 55 0 21 1 45 0 15 1 52 0 8 1 62 0 17 1 62 0 12 1 53 0 104 0 61 1
9 1 41 1 56 1 51 1 35 1 61 1 52 1 41 1 68 1 31 1 77 0 71 1 84 1 71 1 8 1 51 1
36 1 61 1 72 1 51 1 36 1 41 1 48 1 31 1 26 1 41 1 108 1 31 1 5 1 41 1 108 0 52 1
26 1 52 1 14 1 62 1 115 1 52 1 52 1 42 1 5 0 25 1 18 1 42 1 36 1 52 1 9 1 62 1
10 1 43 1 9 1 53 1 18 1 43 1 6 1 43 1
;
run; proc print;

Calcite | Level 5

## Re: Plotting the log hazard/survival vs a variable

Hi Reeza,

This is not a real data set. It is a small data set that I have created just practice. I'm currently using SAS studio.

data kidney;
input time cens age nephrectomy @@;
cards;
9 1 50 0 6 1 55 0 21 1 45 0 15 1 52 0 8 1 62 0 17 1 62 0 12 1 53 0 104 0 61 1
9 1 41 1 56 1 51 1 35 1 61 1 52 1 41 1 68 1 31 1 77 0 71 1 84 1 71 1 8 1 51 1
36 1 61 1 72 1 51 1 36 1 41 1 48 1 31 1 26 1 41 1 108 1 31 1 5 1 41 1 108 0 52 1
26 1 52 1 14 1 62 1 115 1 52 1 52 1 42 1 5 0 25 1 18 1 42 1 36 1 52 1 9 1 62 1
10 1 43 1 9 1 53 1 18 1 43 1 6 1 43 1
;
run; proc print;
proc phreg data=kidney plots= survival;
model time*cens(0)= age nephrectomy;
run;

I just want to get a plot of mode time*cens(0)= age

Thank you,

Calcite | Level 5

## Log hazards

Hi,

I'm using survival data and I want to plot the log hazard of the outcome vs age (a variable in my data set) to see if the relationship between age and the log hazard is linear, but I'm not sure how to create such a plot.

For example, how would make the plot using this data set:

data kidney;
input time cens age nephrectomy @@;
cards;
9 1 50 0 6 1 55 0 21 1 45 0 15 1 52 0 8 1 62 0 17 1 62 0 12 1 53 0 104 0 61 1
9 1 41 1 56 1 51 1 35 1 61 1 52 1 41 1 68 1 31 1 77 0 71 1 84 1 71 1 8 1 51 1
36 1 61 1 72 1 51 1 36 1 41 1 48 1 31 1 26 1 41 1 108 1 31 1 5 1 41 1 108 0 52 1
26 1 52 1 14 1 62 1 115 1 52 1 52 1 42 1 5 0 25 1 18 1 42 1 36 1 52 1 9 1 62 1
10 1 43 1 9 1 53 1 18 1 43 1 6 1 43 1
;
run; proc print;

I want to get a plot of model time*cens(0)=age

## Re: Log hazards

Consider this SAS example using PROC LIFETEST: Example 70.3 Life-Table Estimates for Males with Angina Pectoris, which includes "and estimated hazard function are requested by the PLOTS= option".

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Calcite | Level 5

## Re: Log hazards

thank you!

Calcite | Level 5

## Re: Log hazards

I'm actually trying to create a plot just similar to the one below. I tried Proc Phreg, but it does not create such plot.

SAS Super FREQ

## Re: Log hazards

Did you try using the TRANSFORM=LOG option on the PROC PHREG statement, as described in the doc?

Calcite | Level 5

## Re: Log hazards

Hi,

No, I have not tried that yet, but the proc phreg does not create a hazard rate plot. If I were to use that option, I'm not sure which function I should to transform.

Thanks

Calcite | Level 5

## Re: Log hazards

Hi @Rick_SAS,

so if this is my SAS code:

proc phreg data=kidney plots=cumhaz ;
model time*cens(0)=age / rl ;

run;

how do I use the transform statement to take the log of the cumhaz.

SAS Super FREQ

## Re: Log hazards

I was wrong when I said that you could use the TRANSFORM= option in PROC PHREG.

However, you can create an output data set from any table or graph that SAS produces. Please see

Thus the easiest way to accomplish your task is to write the cumulative hazard values to a data set and then simply tell PROC SGPLOT to use a log axis, like this:

``````proc phreg data=kidney plots=cumhaz ;
model time*cens(0)=age / rl ;
ods output CumHazPlot=CHPlot;
run;

title "log10(cumulative hazard) for Age=49.39";
proc sgplot data=CHPlot;
where CumHaz>0;
step y=CumHaz x=Time;
yaxis type=log logbase=10 logstyle=logexpand;
run;``````

Alternatively, you can use the DATA step to log-transform the cumulative hazard, and then use a regular (linear) scale on the axis:

``````data logCumHaz;
set CHPlot;
if cumHaz=0 then logCumHaz=.;
else logCumHaz= log10(cumHaz);
label logCumHaz = "log10(cumulative hazard)";
run;

title "log10(cumulative hazard) for Age=49.39";
proc sgplot data=logCumHaz;
step y=logCumHaz x=Time;
run;``````

Calcite | Level 5

## Re: Log hazards

@Rick_SAS Thank you for your help. This is exactly what I wanted to do, but I want to plot age instead of time on the x-axis. When I change the x-axis to age, I get an error message saying that the variable age is not found. So I'm guessing that the variable age is not found in the new data set "CHPlot". So how do I include age in the new dataset "CHPlot".

Thank you so much for your help, I really appreciate it.

SAS Super FREQ

## Re: Log hazards

In looking back at your original post, I see that you did mention plotting against age, which is a covariate. Thus my idea will not work.I suggest you look at the OUTPUT statement or the STORE statements to get the information that you want. This now sounds like a statistical question rather than a graphing question. I do not use PHREG myself, so I will defer to those with more experience.  Good luck.

Super User