I am plotting the values for two series, peer salaries and UA average salaries by year and rank. I am using PROC SGPLOT and two series statements with the year as the x value and the salaries as the y value, then the rank is the group variable. I have SAS 9.2. I want the legend to simply show that the first series is the peer salary and the second is the UA average salary, not show the group (rank) values. Even using the legendlabel option, I can't seem to make this happen. My code and results are below. Suggestions are greatly appreciated!
proc sgplot data=faculty noautolegend;
where uasrank in ('1','2','3');
series x=uasyear y=uassug50/group=uasrank
markers
markerattrs=(symbol=circlefilled)
lineattrs=(color=black pattern=solid)
legendlabel="SUG 50th Percentile"
name="sug50" datalabel=label;
series x=uasyear y=uasuaavg/group=uasrank
markers
markerattrs=(symbol=squarefilled)
lineattrs=(color=CX990000 pattern=solid)
legendlabel="UA Average"
name="uaavg";
keylegend "sug50" "uaavg";
xaxis label='';
yaxis label='';
format uasrank $fac_rank. uasyear $year. uassug50 dollar12. uasuaavg dollar12.;
run;
Several people from SAS helped me with this, and I appreciate all their work. It looks like, as I always suspect, that you can do most anything in SAS even if not in a totally direct way. Here is the answer that worked for me, given by Sanjay Matange:
data faculty;
set faculty;
a=.;
if _n_ = 1 then a=0;
run;
proc sgplot data=faculty noautolegend;
where uasrank in ('1','2','3');
series x=uasyear y=uassug50/group=uasrank
markers
markerattrs=(symbol=circlefilled)
lineattrs=(pattern=solid color=black)
curvelabel
curvelabelpos=start;
series x=uasyear y=uasuaavg/group=uasrank
markers
markerattrs=(symbol=squarefilled)
lineattrs=(pattern=solid color=CX990000)
curvelabel
curvelabelpos=end;
series x=uasyear y=a / lineattrs=graphdata1(color=black pattern=solid)
name='a' legendlabel="SUG 50th Percentile";
series x=uasyear y=a / lineattrs=graphdata2(color=CX990000 pattern=solid)
name='b' legendlabel="UA Average";
keylegend "a" "b";
xaxis label=' ';
yaxis label=' ' min=50000;;
format uasyear $year. uasrank $fac_rank. uassug50 dollar12. uasuaavg dollar12.;
run;
You could use two KEYLEGEND statements with different titles. If you specify the same location and position for both legends they will be correctly stacked. (hope this is not new to 9.3)
PG
Several people from SAS helped me with this, and I appreciate all their work. It looks like, as I always suspect, that you can do most anything in SAS even if not in a totally direct way. Here is the answer that worked for me, given by Sanjay Matange:
data faculty;
set faculty;
a=.;
if _n_ = 1 then a=0;
run;
proc sgplot data=faculty noautolegend;
where uasrank in ('1','2','3');
series x=uasyear y=uassug50/group=uasrank
markers
markerattrs=(symbol=circlefilled)
lineattrs=(pattern=solid color=black)
curvelabel
curvelabelpos=start;
series x=uasyear y=uasuaavg/group=uasrank
markers
markerattrs=(symbol=squarefilled)
lineattrs=(pattern=solid color=CX990000)
curvelabel
curvelabelpos=end;
series x=uasyear y=a / lineattrs=graphdata1(color=black pattern=solid)
name='a' legendlabel="SUG 50th Percentile";
series x=uasyear y=a / lineattrs=graphdata2(color=CX990000 pattern=solid)
name='b' legendlabel="UA Average";
keylegend "a" "b";
xaxis label=' ';
yaxis label=' ' min=50000;;
format uasyear $year. uasrank $fac_rank. uassug50 dollar12. uasuaavg dollar12.;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.