I'm trying to create a survival plot where the labels on Subjects at Risk are different than what is shown in the legend. I'm also having some difficulty in getting some space between the plot and the xaxistable so that the label "Subjects at Risk" is not overwriting the x axis label in the plot.
So to summarize
1. I need a legend in the plot with the full treatment names along with censored.
2. I need space between the xaxistable and x-axis label so the xaxistable can have its own label.
It would be optimal if I could have one legend with the two treatments and censored in it, but I cannot tell from the documentation if that is doable.
Hello,
Did you see my suggestion to use TITLE= to add a header for the XAXISTABLE?
If you want to have your legends list your treatments and then have a single row for censored (like in the macro that I linked to you), then you can do the following trick:
proc sgplot data=tinterv dattrmap=myattrmap ;
step x=time y=survival / group=stratuma lineattrs=(thickness=1.75px) name='s' attrid = myid;
/**Make a non-grouped plot that you can control the legend label and color on. Gets masked by the colored one afterwards.**/
scatter x=time y=censored / name='c' markerattrs=(color=black size=0pt) legendlabel="Censored";
scatter x=time y=censored / group=stratuma attrid = myid datalabelattrs =(family = "Courier New" size = 9);
xaxistable atrisk / labelattrs = (family="Courier New" size = 9) label x=tatrisk class=stratuma location=outside position = bottom valueattrs = (family= "Courier New" size = 9) title="Patients-at-Risk";
keylegend "s" "c"/ location=inside position = topright valueattrs = (family = "Courier New" size = 9) across=1 autoitemsize;
yaxis min=0 labelattrs=(family="Courier New" size = 9);
xaxis labelattrs =(family = "Courier New" size = 9) values=(0 to 300 by 60);
run;
I make a non-grouped plot of the censors that you can then add to the legend to have a single row legend item. Legendlabel lets me assign the text to be used in the legend (e.g. "Censored"). AUTOITEMSIZE will match the symbol size to the font size.
I remove the name option from the original scatter so that this one won't go into the legend. I added the step plot to the legend statement to include your treatment values above the censored legend.
I added the title= option to the xaxistable to give a header for the patients-at-risk. There might be an option to align this differently, I don't know off hand.
My NEWSURV macro an do all of this for you as well.
If i understand your request correctly then I run my macro newsurv can do this for you if you're interested Macro link.
Otherwise I think the title option in the x axis table can add a label for the patients at risk separate from the x axis label.
AS a minimum show the code you are using now. It wouldn't hurt to provide some example data.
SG Plot code follows - I have annotations and attribute maps attached but that works fine:
proc sgplot data=tinterv dattrmap=myattrmap ;
step x=time y=survival / group=stratuma lineattrs=(thickness=1.75px) name='s' attrid = myid;
scatter x=time y=censored / group=stratuma name='c' attrid = myid datalabelattrs =(family = "Courier New" size = 9);
xaxistable atrisk / labelattrs = (family="Courier New" size = 9) label x=tatrisk class=stratuma location=outside position = bottom valueattrs = (family= "Courier New" size = 9) ;
keylegend "c" / location=inside position = topright valueattrs = (family = "Courier New" size = 9) title = "Censored" titleattrs=(family = "Courier New" size=9);
yaxis min=0 labelattrs=(family="Courier New" size = 9);
xaxis labelattrs =(family = "Courier New" size = 9) values=(0 to 300 by 60);
run;
Is TINVER the output from a PROC? Can you provide data so we can run it?
TINVER is the ODS output file from PROC LIFETEST
SurvivalPlot = tinterv
Then the stratum is recoded to the actual treatment names. I cannot send the data as they are confidential.
Use fake data from the documentation then. Or something along those lines.
@Doug____ wrote:
TINVER is the ODS output file from PROC LIFETEST
SurvivalPlot = tinterv
Then the stratum is recoded to the actual treatment names. I cannot send the data as they are confidential.
Hello,
Did you see my suggestion to use TITLE= to add a header for the XAXISTABLE?
If you want to have your legends list your treatments and then have a single row for censored (like in the macro that I linked to you), then you can do the following trick:
proc sgplot data=tinterv dattrmap=myattrmap ;
step x=time y=survival / group=stratuma lineattrs=(thickness=1.75px) name='s' attrid = myid;
/**Make a non-grouped plot that you can control the legend label and color on. Gets masked by the colored one afterwards.**/
scatter x=time y=censored / name='c' markerattrs=(color=black size=0pt) legendlabel="Censored";
scatter x=time y=censored / group=stratuma attrid = myid datalabelattrs =(family = "Courier New" size = 9);
xaxistable atrisk / labelattrs = (family="Courier New" size = 9) label x=tatrisk class=stratuma location=outside position = bottom valueattrs = (family= "Courier New" size = 9) title="Patients-at-Risk";
keylegend "s" "c"/ location=inside position = topright valueattrs = (family = "Courier New" size = 9) across=1 autoitemsize;
yaxis min=0 labelattrs=(family="Courier New" size = 9);
xaxis labelattrs =(family = "Courier New" size = 9) values=(0 to 300 by 60);
run;
I make a non-grouped plot of the censors that you can then add to the legend to have a single row legend item. Legendlabel lets me assign the text to be used in the legend (e.g. "Censored"). AUTOITEMSIZE will match the symbol size to the font size.
I remove the name option from the original scatter so that this one won't go into the legend. I added the step plot to the legend statement to include your treatment values above the censored legend.
I added the title= option to the xaxistable to give a header for the patients-at-risk. There might be an option to align this differently, I don't know off hand.
My NEWSURV macro an do all of this for you as well.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.