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

Hi,

I am trying to create a simple series plot and assign custom label to each series plot so it is properly shown in chart legend.  However, my chart legend only shows the "by value" instead of the label that should go with the series plot.  Any help would be appreciated.

Output: I should have four series plots for each by value- in each chart, the legend for all 4 series plots are the same and equal to the by value.

code:

/* I tried to add a label to each column in the hope that it would get picked up in the chart legend but no luck.... Smiley Sad */

proc datasets library = Work nolist ;

    modify Load_factor_sgip ;

    label Res = 'Residential'

          Com = 'Commercial'

          Ind = 'Industrial'

          Agr = 'Agriculture & Water Pumping'

        ;

run ;

quit ;

options nobyline orientation = landscape ;

ods graphics on / height = 6 in width = 10.5 in ;

    ods rtf file = 'C:\Documents and Settings\Load_factor_charts.rtf'

        style = statistical nogtitle ;

        ods listing close ; /* close reporting to output window */

        ods results = off ; /* close output to results window */

        title "Sector Load factors for: #byval1" ;

        proc sgplot data = Load_factor_sgip ;

            by PA ;

            series x = Year y = Res / group = PA markers

                lineattrs = (pattern = solid thickness = 2)

               legendlabel = 'Residential'

            ;

            series x = Year y = Com / group = PA markers

                lineattrs = (pattern = solid thickness = 2)

               legendlabel = 'Commercial'

            ;

            series x = Year y = Ind / group = PA markers

                lineattrs = (pattern = solid thickness = 2)

                   legendlabel = 'Industrial'

            ;

            series x = Year y = Agr / group = PA markers

                lineattrs = (pattern = solid thickness = 2)

               legendlabel = 'Agriculture'

            ;

            format Res percent10.2 Com percent10.2

                   Ind percent10.2 Agr percent10.2

            ;

            yaxis label = 'Load Factor' grid ;

            xaxis values = (1990 to 2022 by 4) display = (nolabel) ;

            keylegend / location = inside across = 1 ;

        run ;

        ods listing ;

        ods results = on ;

    ods rtf close ;

ods graphics off ;

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

The LegendLabel is used only when the series plot does not use the GROUP option.  In such a case each series statement creates one series plot and you can identify it with the label you want.

However, when GROUP option is used, a series is drawn for each unique value of the group variable.  So one series statement can produce multiple series in the graph.  In this case, each series is identified by the group value itself.  LegendLabel is ignored.  You can use a format to change the value displayed.


View solution in original post

3 REPLIES 3
Jay54
Meteorite | Level 14

The LegendLabel is used only when the series plot does not use the GROUP option.  In such a case each series statement creates one series plot and you can identify it with the label you want.

However, when GROUP option is used, a series is drawn for each unique value of the group variable.  So one series statement can produce multiple series in the graph.  In this case, each series is identified by the group value itself.  LegendLabel is ignored.  You can use a format to change the value displayed.


DanH_sas
SAS Super FREQ

To build onto what Sanjay said, You might be able to get the desired result by simply removing the GROUP variable. The attributes for the series plots will automatically cycle within each BY-group. The legend labels will also be used. Give that a try and see if that works for you.

Thanks!

Dan

asishgautam
Calcite | Level 5

Ah man now I see my mistake.  Hate to waste everyones time on something like this but thanks for all the help Sanjay and Dan.

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
  • 3 replies
  • 1042 views
  • 3 likes
  • 3 in conversation