Programming the statistical procedures from SAS

Plotting cumulative hazard rate (Nelson Aalen curves)

New Contributor
Posts: 4

Plotting cumulative hazard rate (Nelson Aalen curves)

Hello everyone,


I am working on survival data with incidence of cancer and some food consumption data in quartiles.

Exposition : quartile of sugared food

Confusion factor : age, BMI, sex.

Outcome : cancer


I would like to draw a curve of cumulative hazard rate function (for example with Nelson Aalen estimator, a non parametric estimator of the cumulative hazard rate function) like this graph below : where we would see the cumulative risk of cancer in function of the 4 quartiles of food consumption.

nelson Aalen curve.JPG

Caption of the graph : "Nelson-Aalen curves showing the outcome of new-onset overweight depending on ultraprocessed food consumption at baseline. Adjusted for sex, age, marital status, educational status"


If someone had an idea of a beginning of script, i would be really grateful.

i am doing Cox model with this type of script :

proc phreg data=mydata;
class sexe;
model survival_time*censure(1)=sexe age IMC;
strata quartile_ultraprocessed ;

Thanks in advance, have a nice day,

Super User
Posts: 18,569

Re: Plotting cumulative hazard rate (Nelson Aalen curves)

Have you tried adding the PLOTSooption to your PROC statement?


You'll want tthe 'statistical' style to get the curves in a similar format but you'll have to manually add the data at the top. If you can post it at the bottom of the graph that could be more easily incorporated.



Super Contributor
Posts: 287

Re: Plotting cumulative hazard rate (Nelson Aalen curves)

You can get the cumulative hazard (Nelson Aalen) by using the baseline statement in PHREG;


As Nelson Aalen only can account for one combination of covariates at a time you will need to put all covariates into the strata statement.


Here is a simple example:

data test;
do i=1 to 100;

proc phreg data=test;
  model t=;
  strata x;
  baseline out=baseline cumhaz=cumhaz;

You can then plot the hazard by using proc gplot or sgplot.


New Contributor
Posts: 4

Re: Plotting cumulative hazard rate (Nelson Aalen curves)

thanks for your answers.

I tested your statements but I don't know why when I look at the table "baseline" created and containing "Cumulative Hazard function estimates", there are only about 2000 observations. And in my dataset of departure, I have about 100 000 observations (about 2200 events and 97 800 censored). Do you have an idea why I have this decrease ?


have a nice day,

Super Contributor
Posts: 287

Re: Plotting cumulative hazard rate (Nelson Aalen curves)

the estimated cumulative hazard function only has as many jumps (its a step function) as there are uncensored events. So wiht 2200 events it should have 2200 observations.

Ask a Question
Discussion stats
  • 4 replies
  • 3 in conversation