data Concordance_MAP;
input Measure $ DV: $15. IV: $15. CC LCL UCL ;
datalines;
LA BI_A_MAP BI_LA_MAP 0.5813 0.4376 0.696
LL BI_A_MAP BI_LL_MAP 0.3992 0.1926 0.5719
Nex BI_A_MAP BI_Nex_MAP 0.6511 0.5149 0.7553
UA BI_A_MAP BI_UA_MAP 0.5274 0.356 0.6644
LA i3min_A_MAP i3min_LA_MAP 0.5942 0.4548 0.7051
LL i3min_A_MAP i3min_LL_MAP 0.2979 0.0579 0.5054
Nex i3min_A_MAP i3min_Nex_MAP 0.8376 0.764 0.8897
UA i3min_A_MAP i3min_UA_MAP 0.2369 0.049 0.4086
LA i15min_A_MAP i15min_LA_MAP 0.6234 0.4911 0.7275
LL i15min_A_MAP i15min_LL_MAP 0.5584 0.3475 0.7155
Nex i15min_A_MAP i15min_Nex_MAP 0.6498 0.5169 0.7521
UA i15min_A_MAP i15min_UA_MAP 0.5681 0.4265 0.6825
LA i30min_A_MAP i30min_LA_MAP 0.6298 0.4908 0.7376
LL i30min_A_MAP i30min_LL_MAP 0.5181 0.3028 0.6831
Nex i30min_A_MAP i30min_Nex_MAP 0.6895 0.5624 0.7848
UA i30min_A_MAP i30min_UA_MAP 0.6076 0.4677 0.7178
LA i45min_A_MAP i45min_LA_MAP 0.6877 0.5604 0.7832
LL i45min_A_MAP i45min_LL_MAP 0.4402 0.2084 0.6252
Nex i45min_A_MAP i45min_Nex_MAP 0.7509 0.6422 0.83
UA i45min_A_MAP i45min_UA_MAP 0.5898 0.4348 0.7108
LA p3min_A_MAP p3min_LA_MAP 0.5436 0.3843 0.6714
LL p3min_A_MAP p3min_LL_MAP 0.4575 0.2335 0.6353
Nex p3min_A_MAP p3min_Nex_MAP 0.6559 0.5297 0.7538
UA p3min_A_MAP p3min_UA_MAP 0.424 0.2609 0.5636
;
run;
/* ods listing style=listing; */
proc template;
define style mystyle;
parent=styles.sasweb;
class graphwalls /
frameborder=off;
class graphbackground /
color=white;
end;
run;
ods listing close;
ods html style=mystyle path='.' file='newgraph.html';
ods graphics / reset=all border=off width=600 height=480;
proc sgplot data=Concordance_MAP nowall noborder ;
title 'Concordance coefficient by time';
styleattrs datacontrastcolors=(CX016381 CX1BC9FF CXFF7F00 CX814101 ) ;
scatter x=DV y=CC / group=IV yerrorlower=LCL yerrorupper=UCL noerrorcaps markerattrs=(symbol=circlefilled size =5 )
groupdisplay=cluster clusterwidth =0.2;
yaxis display =(noticks nolabel noline) VALUEATTRS=(Color=Black Family=Arial Size=8 Style=Normal Weight=Normal) ;
xaxis display =(noticks nolabel noline) VALUEATTRS=(Color=Black Family=Arial Size=8 Style=Normal Weight=Normal);
refline 0.75 / axis=y discretethickness=1 lineattrs=(color=cxd0e0f0) LABEL = ('0.75');
run;
I tried entering a keylegend statement before the "run" line, specifying "Measure" as the categorical variable I wanted to be described in the kelegend using the colours : CX016381 CX1BC9FF CXFF7F00 CX814101.
It is not making a difference so don't know whet the error is. Without the keylegend statement I just get a decryption for "IV"
Also I'm getting this error:
If I understand correctly, you are grouping by a variable you don't want in your legend but want the values of another variable. Here's a quick trick to do this:
ods graphics / reset=all border=off width=600 height=480;
proc sgplot data=Concordance_MAP nowall noborder ;
title 'Concordance coefficient by time';
styleattrs datacontrastcolors=(CX016381 CX1BC9FF CXFF7F00 CX814101 ) ;
scatter x=DV y=CC / group=IV yerrorlower=LCL yerrorupper=UCL noerrorcaps markerattrs=(symbol=circlefilled size =5 )
groupdisplay=cluster clusterwidth =0.2;
scatter x=dv y=cc / group=measure markerattrs=(size=0pt) name='scatter';
keylegend 'scatter' / position=bottom location=outside autoitemsize title='Measures';
yaxis display =(noticks nolabel noline) VALUEATTRS=(Color=Black Family=Arial Size=8 Style=Normal Weight=Normal) ;
xaxis display =(noticks nolabel noline) VALUEATTRS=(Color=Black Family=Arial Size=8 Style=Normal Weight=Normal);
refline 0.75 / axis=y discretethickness=1 lineattrs=(color=cxd0e0f0) LABEL = ('0.75');
run;
I add a scatter plot to your graph that groups by measure, I name it "scatter," and I enter only that scatter plot into the keylegend. It keeps the values of measure that you can then show in the legend. The new scatter plot has a size of 0pt so it won't show up in the graph.
Ok so I was able to get a keylegend by specifying "Measures" instead of "IV":
But I can't control the appearance or location of this keylegend with a keylegend statement.
proc sgplot data=Concordance_MAP_lab nowall noborder ;
title 'Concordance coefficient by time';
styleattrs datacontrastcolors=(CX016381 CX1BC9FF CXFF7F00 CX814101 ) ;
scatter x=DV y=CC / group=Measure yerrorlower=LCL yerrorupper=UCL noerrorcaps markerattrs=(symbol=circlefilled size =5 )
groupdisplay=cluster clusterwidth =0.2;
yaxis display =(noticks nolabel noline) VALUEATTRS=(Color=Black Family=Arial Size=8 Style=Normal Weight=Normal) ;
xaxis display =(noticks nolabel noline) VALUEATTRS=(Color=Black Family=Arial Size=8 Style=Normal Weight=Normal);
refline 0.75 / axis=y discretethickness=1 lineattrs=(color=cxd0e0f0) LABEL = ('0.75');
/* keylegend "Measure"/location=outside; */
run;
Hello, Try adding a name="something" option to your scatter statement and then put that name reference into your keylegend. When you type something in the keylegend statement it has to match a reference from a NAME option in the graph statements. When you specify a text that doesn't exist in a name reference then it doesn't have a legend to plot.
e..g
scatter x=DV y=CC / group=Measure yerrorlower=LCL yerrorupper=UCL noerrorcaps markerattrs=(symbol=circlefilled size =5 )
groupdisplay=cluster clusterwidth =0.2 Name="scatter";
keylegend "scatter" / ...;
Thank you Jeff!
Worked perfectly and I was able to position it where I needed.
Christos
If I understand correctly, you are grouping by a variable you don't want in your legend but want the values of another variable. Here's a quick trick to do this:
ods graphics / reset=all border=off width=600 height=480;
proc sgplot data=Concordance_MAP nowall noborder ;
title 'Concordance coefficient by time';
styleattrs datacontrastcolors=(CX016381 CX1BC9FF CXFF7F00 CX814101 ) ;
scatter x=DV y=CC / group=IV yerrorlower=LCL yerrorupper=UCL noerrorcaps markerattrs=(symbol=circlefilled size =5 )
groupdisplay=cluster clusterwidth =0.2;
scatter x=dv y=cc / group=measure markerattrs=(size=0pt) name='scatter';
keylegend 'scatter' / position=bottom location=outside autoitemsize title='Measures';
yaxis display =(noticks nolabel noline) VALUEATTRS=(Color=Black Family=Arial Size=8 Style=Normal Weight=Normal) ;
xaxis display =(noticks nolabel noline) VALUEATTRS=(Color=Black Family=Arial Size=8 Style=Normal Weight=Normal);
refline 0.75 / axis=y discretethickness=1 lineattrs=(color=cxd0e0f0) LABEL = ('0.75');
run;
I add a scatter plot to your graph that groups by measure, I name it "scatter," and I enter only that scatter plot into the keylegend. It keeps the values of measure that you can then show in the legend. The new scatter plot has a size of 0pt so it won't show up in the graph.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.