BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
djbateman
Lapis Lazuli | Level 10

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?

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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

3 REPLIES 3
DanH_sas
SAS Super FREQ

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

djbateman
Lapis Lazuli | Level 10

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

ballardw
Super User

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

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!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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