BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
crkraft
Calcite | Level 5

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;

SGPlot4.png

1 ACCEPTED SOLUTION

Accepted Solutions
crkraft
Calcite | Level 5

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;

SGPlot4.png

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

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

PG
crkraft
Calcite | Level 5

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;

SGPlot4.png

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2656 views
  • 0 likes
  • 2 in conversation