Data visualization with SAS programming

Suppress LEGENDLABEL option

Accepted Solution Solved
Reply
Regular Contributor
Posts: 228
Accepted Solution

Suppress LEGENDLABEL option

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?


Accepted Solutions
Solution
‎10-29-2012 11:37 AM
SAS Super FREQ
Posts: 925

Re: Suppress LEGENDLABEL option

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

View solution in original post


All Replies
Solution
‎10-29-2012 11:37 AM
SAS Super FREQ
Posts: 925

Re: Suppress LEGENDLABEL option

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

Regular Contributor
Posts: 228

Re: Suppress LEGENDLABEL option

I saw that NAME option, but I was not getting what it was doing.  That makes complete sense now.  Thank you!

Super User
Posts: 11,134

Re: Suppress LEGENDLABEL option

Crude but I would try to assign a single null character (ASCII 255) as the label.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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