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

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;

 

 

Thank you in advance,

Ahmad

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

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

--------------------------

View solution in original post

13 REPLIES 13
Reeza
Super User

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?

 


@Ahmad1 wrote:

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;

 

 

Thank you in advance,

Ahmad


 

Ahmad1
Calcite | Level 5

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,

Ahmad

Ahmad1
Calcite | Level 5

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

 

 

Thank you in advance,

Ahmad

mkeintz
PROC Star

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

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

thank you!

Ahmad1
Calcite | Level 5

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.

Rick_SAS
SAS Super FREQ

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

 

Ahmad1
Calcite | Level 5

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

Ahmad1
Calcite | Level 5

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.

 

Thanks for your help

Rick_SAS
SAS Super FREQ

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;

 

Ahmad1
Calcite | Level 5

@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. 

Rick_SAS
SAS Super FREQ

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.

Reeza
Super User

@Ahmad1 please do not post the same question multiple times. 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 13 replies
  • 5082 views
  • 0 likes
  • 4 in conversation