BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Whitlea
Obsidian | Level 7

I want to bold one of the legend labels in my proc sgplot. 

Here are my current results, highlighted is what I want in bold ("A"):

Capture.PNG

 

 

 

 

 

 

 

 

 

 

 

Here is my code:

proc sgplot data=final noborder ;  

series x=date y=&y1/ datalabel=&y1 DATALABELATTRS=(family='Roboto' SIZE=10pt weight=bold color=black)DATALABELPOS=top
MARKERS MARKERATTRS=(SYMBOL=CircleFilled color=red size=8) LINEATTRS = (color=red pattern=solid THICKNESS=3) legendlabel= "A" ;

series x=date y=&y2 / datalabel=&y2 DATALABELATTRS=(family='Roboto' SIZE=10pt color=black)DATALABELPOS=bottom
MARKERS MARKERATTRS=(SYMBOL=CircleFilled color=blue size=8) LINEATTRS = (color=blue pattern=solid THICKNESS=3) legendlabel= "B";

yaxis  grid VALUES = (&values) display=(noline noticks) valueATTRS=(family='Roboto' size=10pt)
label=" " LABELATTRS=(family='Roboto' size=10pt);

XAXIS TYPE = LINEAR  display=( noline noticks)label=" "
LABELATTRS=(family='Roboto' size=10pt ) valueATTRS=(family='Roboto' size=10pt ) ;

keylegend / noborder location=outside position=bottom valueATTRS=(family='Roboto' size=10pt)  ;
title &TITLE1 ;

run;

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

To apply different legend appearance to different plots the steps are:

1) Provide a name to each plot you want to appear

2) Provide a different Keylegend statement referencing the name with the attributes.

 

Here is an example that sets one legend with green for the value text in bold text.

proc sgplot data=sashelp.class;
   scatter x=age y=height/name='h' ;
   scatter x=age y=weight/name='w' ;
   keylegend 'h'/ position=bottom  valueattrs=(color=green weight=bold);
   keylegend 'w'/  position=bottom  ;
run;

You do have to provide the second (or other) keylegend statements otherwise the names not references will not appear in the legend. There will be some interaction between positions and such to play with

View solution in original post

2 REPLIES 2
ballardw
Super User

To apply different legend appearance to different plots the steps are:

1) Provide a name to each plot you want to appear

2) Provide a different Keylegend statement referencing the name with the attributes.

 

Here is an example that sets one legend with green for the value text in bold text.

proc sgplot data=sashelp.class;
   scatter x=age y=height/name='h' ;
   scatter x=age y=weight/name='w' ;
   keylegend 'h'/ position=bottom  valueattrs=(color=green weight=bold);
   keylegend 'w'/  position=bottom  ;
run;

You do have to provide the second (or other) keylegend statements otherwise the names not references will not appear in the legend. There will be some interaction between positions and such to play with

Ksharp
Super User

You could customize legend by LEGENDITE statement to make it happen.

But make sure the item of legend is consistent/same within GRAPH (you can PROC SORT it before).

 

data have;
set sashelp.heart(obs=1000);
run;

proc sort data=have ;by sex ;run;
proc sgplot data=have;
scatter x=weight y=height/group=sex ;
legenditem name='a' type=MARKERLINE / label='Female' labelattrs=(weight=bold) MARKERATTRS=(symbol=circlefilled color= blue) LINEATTRS=(color= blue);
legenditem name='b' type=MARKERLINE / label='Male' MARKERATTRS=(symbol=circlefilled color= red) LINEATTRS=(color= red);
keylegend 'a' 'b'/title='Sex:';
run;

Ksharp_0-1734058871305.png

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 296 views
  • 3 likes
  • 3 in conversation