BookmarkSubscribeRSS Feed
Kels123
Quartz | Level 8

Hi SAS Community,

 

I found a way to tailor my Kaplan-Meier plots to present the data I need to show, including number of subjects at risk. The only issue is that now I need to add the number censored in brackets next to the number at risk at each time point (every 500 days). I don't know how to modify the code to do this. The only option I have at the moment is the calculate the number censored by hand and add it in at the bottom using powerpoint, which is less than optimal due to formatting issues and potential for human error. Any help would be greatly appreciated. My code is below. Thank you.

 

data _null_;

   %let url = //support.sas.com/documentation/onlinedoc/stat/ex_code/142;

   infile "http:&url/templft.html" device=url;

 

   file 'macros.tmp';

   retain pre 0;

   input;

   _infile_ = tranwrd(_infile_, '&', '&');

   _infile_ = tranwrd(_infile_, '&lt;' , '<');

   if index(_infile_, '</pre>') then pre = 0;

   if pre then put _infile_;

   if index(_infile_, '<pre>')  then pre = 1;

run;

 

%inc 'macros.tmp' / nosource;

 

* Modify the template;

%ProvideSurvivalMacros

%let TitleText0 = "Kaplan-Meier Plot: Probability of death, stratified by CD4 count at time of HIV diagnosis";

%let yOptions = label="Survival Probability"

                linearopts=(viewmin=0.7 viewmax=1 tickvaluelist=(0.7 0.8 0.9 1.0));

%let xOptions = label="Time (days since release)" ;

%let GraphOpts = DataContrastColors=(green red blue)

DataColors=(green red blue);

/*%let TitleText1 = &titletext0 "CD4 count at diagnosis " STRATUMID;*/

%CompileSurvivalTemplates

 

*KM stratified by AIDS STAGE**************************************************************;

proc format ;

invalue CD4_atdiagnosiscat '>=500 cells/µL' = 1 '200-499 cells/µL' = 2 '<200 cells/µL' = 3;

value CD4_atdiagnosisfmt 1 = '>=500 cells/µL' 2 = '200-499 cells/µL' 3 = '<200 cells/µL';

run;

data tempCD4(drop=g);

set CLEAN.databasesurv3(rename=(CD4_atdiagnosis=g));

CD4_atdiagnosis = input(g, CD4_atdiagnosiscat.);

run;

* Analysis;

ods graphics on;

proc lifetest data=work.tempCD4 method=km atrisk

    plots=(S(test nocensor atrisk(maxlen=16 outside(0.12))=0 to 3000 by 500));

    time time*EVENT_ANYDEATH(0);

    strata CD4_atdiagnosis / order=internal adjust=sidak test=logrank ;

label CD4_atdiagnosis = "CD4 count at diagnosis";

    format CD4_atdiagnosis CD4_atdiagnosisfmt.;

run;

ods graphics off;

3 REPLIES 3
WarrenKuhfeld
Rhodochrosite | Level 12

 

This example is from one of my tutorials.  The point is you can construct a macro that adds DRAW statements to enhance the graph in any way.  If you need to make the contents depend on data, you can do that too.  You could use CALL EXECUTE to write the statements.  While this paper does not do what you ask, it shows the incredible lengths you can go to to customize graphs.  https://www.pharmasug.org/proceedings/2018/DV/PharmaSUG-2018-DV03.pdf 

 

%ProvideSurvivalMacros

%macro StmtsBeginGraph; 
  * Coordinates are ad hoc, and there are many 
     available coordinate systems.
     See the documentation for more information.;
  drawtext textattrs=(weight=Bold) 'Number at Risk' / 
                  x=5 y=14 width=9;
%mend;

%CompileSurvivalTemplates

proc lifetest data=sashelp.BMT 
                      plots=survival(atrisk outside maxlen=13);
   time T * Status(0);
   strata Group;
run;

 

lih
Calcite | Level 5 lih
Calcite | Level 5

I have the same question. I want show #in-risk(#censored) at each time interval below KM plot. #censored is #patients who did not have event but lost follow up prior the time point (Censored at last contact), they are hash markers in survival curve.  

Thanks!

 

 

 

WarrenKuhfeld
Rhodochrosite | Level 12

Every customization, of which I was aware that customers wanted before I retired, is illustrated in this chapter. https://support.sas.com/documentation/onlinedoc/stat/151/kaplan.pdf

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Discussion stats
  • 3 replies
  • 2926 views
  • 0 likes
  • 3 in conversation