BookmarkSubscribeRSS Feed
SASuserlot
Barite | Level 11

I am learning SGPLOT to output the KM plots recently, I have some questions how to customize the Kaplan plot output. I tried  to achieve it using the sas documentation, but I am not able to achieve it. I have the questions mentioned in the image. Can you guys please help me to learn the things, also please direct any good references. Thank you in Advance

SASuserlot_0-1636486842286.png


**Dummy data**;

data adtte;
   length paramcd $8 param $100;
   paramcd = "OS";
   param = "Overall Survival";
   do trtpn = 1 to 4;
      trtp = 'Treatment ' || put(trtpn,1.);
      do subjid = 1 to 40;
         aval = 2 + ranuni(1)*24*(trtpn/4);
         cnsr = (ranuni(1)>0.2);
         output;
      end;
   end;
run;

proc sort data=adtte out=km00;
   by trtpn trtp;
   where paramcd = "OS";
run;
proc sql noprint;
   select   distinct strip(param) || " Probability"
   into     :ylabel
   from     km00
   ;
quit;
%let ylabel = &ylabel;
%put &=ylabel;

* creating tick marks on X-axis*;
%let values = 0 2 4 6 8 10 12 14 16 18 20 22 24;
%put &=values;

**format the value 0 as B/L**;
proc format;
   value timefmt
   0 = "B/L"
   other = [best.]
   ;
run;
ods html;
**lifetest**;


ods graphics on;
ods listing close; 

proc lifetest data=km00 plots=(survival(atrisk=&values));
   ods output survivalplot=km10;
   time aval*cnsr(1);
   strata trtpn;
run;

**complete with a format to prevent missing values from showing up as a dot.**;
proc format;
   value xatn
   . = " "
   other = [best.]
   ;
run;

data km20;
   set km10;
   if n(tatrisk) then
      xatn = atrisk;
   format xatn xatn.;
run;

****************************************************************************
Next we add the xaxistable statement. For some reason SAS has us use the 
class= option to create groups in the x-axis table (we use the group= option 
in the step and scatter statements).
*****************************************************************************;
proc sgplot data=km20;
   *--- draw the survival curves ---;
   step y=survival x=time / 
      group=stratumnum
      name="step"
      ;
   *--- draw censor indicators for censoring symbol legend purposes ---;
   scatter y=censored x=time /
      markerattrs=(symbol=circle )   
      name="censor"
      ;
   *--- draw censor indicators ---;
   scatter y=censored x=time /
      group=stratumnum 
      markerattrs=(symbol=circle)
 		;

	*--- add the sample sizes ---;
   xaxistable xatn /
      class=stratumnum
      colorgroup=stratumnum
      ;

   *--- cosmetics ---;
   yaxis
      label="&ylabel"
      ;
   xaxis 
      values=(&values) 
      valueshint
      valuesformat=timefmt.
      label="Weeks" ;

	**--Key legend--> Main heading--**;

   keylegend "step" /
      title="Treatment Group"
      noborder
      linelength=15pct
      outerpad=(bottom=10pt)
      ;
   **---Location of the Censor legend indicator--**;
	  keylegend "censor" / 
      location=inside
      position=bottomleft
      ;
run;
5 REPLIES 5
ChrisHemedinger
Community Manager

Check out the very popular SAS macro(s) created by @JeffMeyers :

 

Kaplan-Meier Survival Plotting Macro %NEWSURV 

A SAS Macro to Perform Kaplan-Meier Multiple Imputation for Survival Analyses with Competing Events 

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
SASuserlot
Barite | Level 11

 I am new KM plot, where I can find  %newsurv macro code?

SASuserlot_0-1636490942703.png

 

ChrisHemedinger
Community Manager

All of the SAS programs are attached to the article. I believe the most recent version is this one.

 

 

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
sbxkoenk
SAS Super FREQ

This is also a popular paper :

 

Paper 427-2013
Creating and Customizing the Kaplan-Meier Survival Plot in PROC LIFETEST
Warren F. Kuhfeld and Ying So, SAS Institute Inc.

https://support.sas.com/resources/papers/proceedings13/427-2013.pdf

 

From the same author :
Creating and customizing the Kaplan-Meier Survival Plot in PROC LIFETEST

https://video.sas.com/detail/video/2918155168001/creating-and-customizing-the-kaplan-meier-survival-...

 

Best regards,

Koen

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5 replies
  • 1828 views
  • 2 likes
  • 4 in conversation