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"):
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!
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
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
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;
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!
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.