BookmarkSubscribeRSS Feed
hpatel3
Obsidian | Level 7

Hi again SAS communities

 

i'm working on a KM curve plotting gender (female vs male survival) and for the life of me I cannot figure out how to get my lines to be different colors

 

 

They're both blue here, and I'd like the female line to be red--and have that shown in the legend label. I feel like I've looked all over the internet and SAS communities to figure it out, and I see absolutely nothing. I'd also like to stay away from Macros if possible. I don't know how to use it. 

 

This is what I have currently: 

libname Hetal "\\tuftsmc\home\hpatel3\SAS Datasets";
run; 
ods graphics on/attrpriority=color;
ods select all;
ods output survivalplot=genderobs;

proc lifetest data=hetal.gender_obskm conftype=loglog plot=(s) plots=(survival(CL strata=panel)) 
timelist=(1 5 10) outs=Survival_Rates reduceout alpha=.05; 
/* Surival_rates gives you confidence intervals in "output data" tab*/
time FU_time*NYHA_stat(0); 
strata gender / test= logrank;
by gender;
where NYHA_Stat=1 AND Obst_Stat=1;
Title "Male patients with obstructive HCM in NYHA Stage III/IV";
run;



proc sgplot data=genderobs noborder nowall cycleattrs;
step x=Time y=Survival/ group=gender lineattrs=(color=darkblue  thickness=2 pattern=solid) name="s"
 legendlabel="obstructive";
 format gender genfmt.; 
xaxis display=(noticks) label="Years" values=(0 to 10 by 5) min=0 max=10 labelattrs=(size=10 weight=bold );
yaxis label='Survival Probability' values=(0 to 1.0 by 0.2) min=0 max=1.0 labelattrs=(size=10 weight=bold);
run;
ods graphics off; 



I think what's wrong is the specific line I've bolded above, but I really don't know at this point what to change. I would settle for females being a dashed line if that's easier. Really just something to differentiate. 

 

Here is what my curve currently looks like: 

 

KM curve male v female.PNG

2 REPLIES 2
joeFurbee
Community Manager

Hi @hpatel3. I think you can find the answer here: http://support.sas.com/kb/35/864.html

 

The sample code listed on that page is:

proc sgplot data=sashelp.class;
  reg x=weight y=height / group=sex degree=3;
  reg x=weight y=height / lineattrs=(color=blue pattern=dash) 
                          markerattrs=(color=black symbol=circlefilled);

 


Join us for SAS Community Trivia

SAS Bowl LIII, SAS Hackathon 2025
Wednesday, August 25, 2025 at 10 am.
hpatel3
Obsidian | Level 7

 

Thanks for replying!

I've been playing around with this a bit and no matter which way what- I'm getting this dumb error in my code. I don't know WHAT exactly I'm missing here. Before I added this stratum and labels stuff in- I wasn't getting these errors, so oh goodness, someone please say they know what I'm doing wrong here. This just feels so silly that I can't change a single color--and have it reflect in the line color that say male or female in the key. It just seems like it would be simple!

 


proc sgplot data=genderobs noborder nowall cycleattrs;
step x=Time y=Survival/ group=gender lineattrs=(color=darkblue  thickness=2 pattern=solid) name="s"
 legendlabel="obstructive";
 format gender genfmt.; 
 series x=time y=Survival/ markerattrs=(symbol=plus) name='Female'; 
 series x=time y=survival / markerattrs=(symbol=plus) group=stratum name='male';
 xaxistable atrisk / x=atrisk class=stratum colorgroup=stratum valueattrs=(weight=bold);
keylegend'Female' / location=outside position=bottomright color=darkblue size=1 style=normal weight=normal);
 keylegend 'Male' / color=rose linelength=18;
 yaxis display=(noticks) label="Survival Probability "values=(0 to 1.0 by 0.2) min=0 max=1.0  ;
xaxis display=(noticks) label="Years" values=(0 to 10 by 5) min=0 max=10;

run;
ods graphics off; 

 

 

km error.PNG

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 3655 views
  • 1 like
  • 2 in conversation