Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Analytics
- /
- Stat Procs
- /
- Cox regression plot - plot two lines in the same graph

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

☑ This topic is **solved**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 09-20-2023 12:48 PM
(446 views)

Hi, we have this dataset:

```
data have;
input ID Lastage group1 group2 Age_trt Event_age;
datalines;
1 12 0 1 2 4
2 13 0 1 4 6
3 11 1 0 3 7
4 12 1 0 2 .
5 14 0 1 2 .
6 12 1 0 7 9
7 11 1 0 1 6nn
8 14 0 1 3 .
9 13 1 0 3 .
10 13 0 1 5 8
;
run;
data sample;
set have;
time2event = coalesce(event_age, lastage) - age_trt;
censor = missing(event_age);
if group1=1 then group=1;
else group=2;
run;
```

Kindly @Reeza advised with coding to obtain KM failure plots. We are not interested in survival but in time to first event. This is the code:

```
ods trace on;
ods output failureplot=sp;
proc lifetest data=sample plots=survival(f)
outsurv=survival_data timelist=(0 to 24 by 2) reduceout;
strata group;
time time2event*censor(1);
run;
proc sgplot data=sp;
step x=time y=_1_survival_/group=stratum name="Percentage of patients reporting the first event";
xaxis values=(0 to 24 by 2) valueshint label="Time to event (Months)";
yaxis offsetmin=0.02 min=0 offsetmax=0.1 max=1.0 label="Percentage of patients reporting the First Event";
scatter x=time y=_1_censored_ / markerattrs=(symbol=plus) name='censored';
scatter x=time y=_1_censored_ / markerattrs=(symbol=plus) GROUP=stratum;
run;
```

Now, we need Cox models. I've used the following:

```
proc phreg data=sample plots=(cumhaz);
class group;
model time2event*censor(1)=group;
baseline /rowid=cohort;
run;
```

I used cumhaz since we are plotting a failure plot. Please correct me if this is wrong.

My main problem is that this code only plots group 2. I checked the output data generated from this code and it also only shows data for group 2. How can the groups be showed in the same graph?

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hello,

Yes , they follow the same pattern.

All lines (groups) can only go up (or stay flat). Because it's cumulative.

The cumulative hazard function and the survival function have a simple monotonic relationship, such that when the Survival function is at its maximum at the beginning of analysis time, the cumulative hazard function is at its minimum. As time progresses, the Survival function proceeds towards it minimum, while the cumulative hazard function proceeds to its maximum.

The cumulative hazard is the negative log of the survival probabilities, i.e. **H(t)=−log(S(t))**.

See here :

INTRODUCTION TO SURVIVAL ANALYSIS IN SAS

https://stats.oarc.ucla.edu/sas/seminars/sas-survival/

You can also calculate the cumulative hazard function using PROC LIFETEST. You don't need a Cox regression for it.

BR, Koen

8 REPLIES 8

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Dear @SanKH1 ,

With respect to your PROC PHREG ...

I think you need to use the BASELINE statement and COVARIATES= option/data set to explicitly identify the two individual CLASS levels for plotting.

Here is a blurb from the PHREG documentation that explains why you are only getting one curve for the reference level of the CLASS variable:

"If the COVARIATES= data set is not specified, a reference set of covariates that consists of the reference levels for the CLASS variables and the average values for the continuous variables is used. For plotting more than one curve, you can use the OVERLAY= global-plot-option to group the curves in separate plots."

This is from the PLOTS= option documentation found here:

SAS/STAT 15.3 User's Guide

The PHREG Procedure

PROC PHREG Statement

Plots= option

https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/statug/statug_phreg_syntax01.htm#statug.ph...

So, if you create a COVARIATES= data set with the two class levels and the appropriate BASELINE statement I think you should get what you want.

```
data covars;
input plt_catg @@;
datalines;
1 2
;
run;
/* And here's the BASELINE statement you then need in PROC PHREG */
BASELINE COVARIATES=covars / ROWID=plt_catg;
```

I don't think you absolutely need the ROWID option on the BASELINE statement but it doesn't look like it would hurt from reading the doc. on the BASELINE statement.

Koen

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi, thank you for looking into this. I ran the following code:

```
data cov;
input group @@;
datalines;
1 2
;
run;
proc phreg data=sample plots(overlay)=(cumhaz);
model timee2event*censor(1)=group / rl;
assess ph/resample;
baseline covariates=cov;
run;
```

This is the graph. But I don't understand why they are exactly the same. Could you please advice?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@SanKH1 wrote:

This is the graph. But I don't understand why they are exactly the same. Could you please advice?

To me the 2 lines (one for each group) are NOT the same.

Why do you think so?

They are not on top of each other.

Koen

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hello,

Yes , they follow the same pattern.

All lines (groups) can only go up (or stay flat). Because it's cumulative.

The cumulative hazard function and the survival function have a simple monotonic relationship, such that when the Survival function is at its maximum at the beginning of analysis time, the cumulative hazard function is at its minimum. As time progresses, the Survival function proceeds towards it minimum, while the cumulative hazard function proceeds to its maximum.

The cumulative hazard is the negative log of the survival probabilities, i.e. **H(t)=−log(S(t))**.

See here :

INTRODUCTION TO SURVIVAL ANALYSIS IN SAS

https://stats.oarc.ucla.edu/sas/seminars/sas-survival/

You can also calculate the cumulative hazard function using PROC LIFETEST. You don't need a Cox regression for it.

BR, Koen

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thank you! This is very helpful.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

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.