I just upgraded to SAS 9.3 last week. I am attempting to redo some of my graphs that I have been producing in SAS 9.1.3 for so long. I came across an issue where I cannot keep certain SCATTER statements from sending a label to the legend.
For example, I run the following code:
proc sgplot data=sdfdata1;
step x=survtime y=survrate1 / lineattrs=(color=black pattern=1) legendlabel='Vynfinit+PLD';
step x=survtime y=survrate2 / lineattrs=(color=black pattern=2) legendlabel='PLD Alone';
scatter x=survtime y=censvalue / markerattrs=(color=black symbol=plus) legendlabel='Censored';
scatter x=timelist y=strata / markerchar=left2 markercharattrs=(color=black) y2axis;
scatter x=timelist y=strata / markerchar=left1 markercharattrs=(color=black) y2axis;
keylegend / across=1 location=inside position=topright noborder;
refline 0;
yaxis offsetmin=0.1 min=0 values=(0 to 1 by .1) label="Probability of PFS";
y2axis offsetmin=0.03 offsetmax=0.93 display=(nolabel noticks);
xaxis values=(0 to 75 by 5) label="Weeks from Randomsation";
run;
quit;
I want to display the legend labels for the STEP statements and the first SCATTER statement; however, I want to suppress the labels for the last two SCATTER statements. If I leave out the LEGENDLABEL option, the it defalts to putting the name of the Y= variable. Is there a way to keep it from printing at all?
Just list the names of the plots you want included in the legend, such as:
proc sgplot data=sdfdata1;
step x=survtime y=survrate1 / lineattrs=(color=black pattern=1) legendlabel='Vynfinit+PLD' name="plot1";
step x=survtime y=survrate2 / lineattrs=(color=black pattern=2) legendlabel='PLD Alone' name="plot2";
scatter x=survtime y=censvalue / markerattrs=(color=black symbol=plus) legendlabel='Censored' name="plot3";
scatter x=timelist y=strata / markerchar=left2 markercharattrs=(color=black) y2axis;
scatter x=timelist y=strata / markerchar=left1 markercharattrs=(color=black) y2axis;
keylegend "plot1" "plot2" "plot3"/ across=1 location=inside position=topright noborder;
refline 0;
yaxis offsetmin=0.1 min=0 values=(0 to 1 by .1) label="Probability of PFS";
y2axis offsetmin=0.03 offsetmax=0.93 display=(nolabel noticks);
xaxis values=(0 to 75 by 5) label="Weeks from Randomsation";
run;
quit;
Hope this helps!
Dan
Just list the names of the plots you want included in the legend, such as:
proc sgplot data=sdfdata1;
step x=survtime y=survrate1 / lineattrs=(color=black pattern=1) legendlabel='Vynfinit+PLD' name="plot1";
step x=survtime y=survrate2 / lineattrs=(color=black pattern=2) legendlabel='PLD Alone' name="plot2";
scatter x=survtime y=censvalue / markerattrs=(color=black symbol=plus) legendlabel='Censored' name="plot3";
scatter x=timelist y=strata / markerchar=left2 markercharattrs=(color=black) y2axis;
scatter x=timelist y=strata / markerchar=left1 markercharattrs=(color=black) y2axis;
keylegend "plot1" "plot2" "plot3"/ across=1 location=inside position=topright noborder;
refline 0;
yaxis offsetmin=0.1 min=0 values=(0 to 1 by .1) label="Probability of PFS";
y2axis offsetmin=0.03 offsetmax=0.93 display=(nolabel noticks);
xaxis values=(0 to 75 by 5) label="Weeks from Randomsation";
run;
quit;
Hope this helps!
Dan
I saw that NAME option, but I was not getting what it was doing. That makes complete sense now. Thank you!
Crude but I would try to assign a single null character (ASCII 255) as the label.
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!
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.