/***************************************************************************************************************** SAS file name: legend.sas File location: __________________________________________________________________________________________________________________ Purpose: To demonstrate 5 tips to control the Lengend in PROC SGPLOT Author: Peter Clemmensen Creation Date: 01/07/2019 This program supports the blog post "" on SASnrd.com *****************************************************************************************************************/ /* Position, Location and Appearance */ proc sgplot data=sashelp.iris noautolegend; styleattrs datasymbols=(circlefilled squarefilled starfilled); scatter x=sepallength y=sepalwidth / group=species; keylegend / location=inside position=NE across=1; run; /* Plot References */ proc sgplot data=sashelp.iris noautolegend; styleattrs datasymbols=(circlefilled squarefilled starfilled); scatter x=sepallength y=sepalwidth / group=species name='scatter'; reg x=sepallength y=sepalwidth / group=species name='reg'; keylegend 'scatter' / location=inside position=NE across=1; run; /* Exclude Groups in the Legend */ proc sgplot data=sashelp.iris noautolegend; styleattrs datasymbols=(circlefilled squarefilled starfilled); scatter x=sepallength y=sepalwidth / group=species name='scatter'; reg x=sepallength y=sepalwidth / group=species name='reg'; keylegend 'scatter' / location=inside position=NE across=1 exclude=('Setosa'); run; /* The Legenditem Statement */ proc sgplot data=sashelp.iris noautolegend; scatter x=sepallength y=sepalwidth / group=species; legenditem type=markerline name='item1' / label="One" lineattrs=(pattern=Solid color=black) markerattrs=(symbol=circlefilled color=red); legenditem type=markerline name='item2' / label="Two" lineattrs=(pattern=Solid color=red) markerattrs=(symbol=circlefilled color=black); keylegend 'item1' 'item2'; run; /* Multiple Legends */ proc sgplot data=sashelp.iris noautolegend; scatter x=sepallength y=sepalwidth / group=species; legenditem type=markerline name='item1' / label="One" lineattrs=(pattern=Solid color=black) markerattrs=(symbol=circlefilled color=red); legenditem type=markerline name='item2' / label="Two" lineattrs=(pattern=Solid color=red) markerattrs=(symbol=circlefilled color=black); keylegend 'item1' / position=NE; keylegend 'item2' / position=SW; run;