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

Hi there,

I customized the barchart from the customer. Now the color of the bars changes in dependent from the value (plus/minus) in red or green. I realized it in the discreteattrmap in proc template.

Now I’ve the problem with the labels of the grouped data in the legend. I can’t setting the legendlabel for this grouped data; every time I get written ‘G’ (for green) and ‘R’ (for red) in the legend.

Where can I set the label for this grouped data in the legend ?

Thank you very much in advanced

Brigitte

~~~~~~~~~~~~~~~ here the code snippet ~~~~~~~~~~~

data WORK.DATA_GRAPH;

input MONAT_TXT $ KER_GESAMT_IST_AJ BAR_COLOR $ KER_GESAMT_IST_VJ ;

datalines;

January 288425 G 300000

February -280184 R -100000

March 652716 G -50000

;

run;

proc template;

                define statgraph ker_graph;

                dynamic _MONAT_TXT

                     _KER_GESAMT_IST_VJ

                     _KER_GESAMT_IST_AJ

                    ;

                begingraph / designheight = 600 designwidth = 1200 border = false;

                entrytitle _id='title' halign=left 'Jahresverlauf operatives Ergebnis' /

                           textattrs=(weight=bold style=normal size=9 family='Arial');

                /* Bars farbig, je nach Wert  */

                discreteattrmap name="colorbysign";

                     value 'G' /fillattrs=(color=green) ;

                     value 'R' /fillattrs=(color=red) ;

                enddiscreteattrmap;

                discreteattrvar attrvar=signvar var=BAR_COLOR attrmap="colorbysign" ;

                layout lattice _id='lattice' /

                     columndatarange=data columngutter=10 rowdatarange=data rowgutter=10;

                layout overlay _id='overlay' /

                       barchart     _id='bar'     x=_MONAT_TXT y=_KER_GESAMT_IST_AJ  /

                                group=signvar legendlabel='XXXXX'

                                dataskin=gloss

                                barlabel=true

                                barlabelattrs=(color=BLACK style=NORMAL family='Arial' size=9

                                barwidth=0.5

                                name='bar'

                                ;

                       seriesplot   _id='series'  x=_MONAT_TXT y=_KER_GESAMT_IST_VJ  /

                                connectorder=xaxis

                                display=(markers)

                                lineattrs=(color=BLUE THICKNESS=3)

                                markerattrs=(symbol=CIRCLEFILLED color=BLUE size=9)

                                name='series';

                 endlayout;

                sidebar /

                    align=bottom spacefill=false;

                       discretelegend _id='legend' 'bar'  'series' /

                       border=true displayclipped=true halign=center opaque=true valign=center

                      valueattrs=(color=BLACK style=NORMAL family='Arial' size=9);

                endsidebar;

                endlayout;

                endgraph;

                end;

           run;

proc sgrender data  = WORK.DATA_GRAPH

          template = KER_GRAPH;

               dynamic            _MONAT_TXT = "MONAT_TXT" 

           _KER_GESAMT_IST_VJ  = "KER_GESAMT_IST_VJ"

                _KER_GESAMT_IST_AJ  = "KER_GESAMT_IST_AJ" 

           ;

           run;

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

LEGENDLABELs do not work in group variable situation. I'm not sure what you want in your legend. Typically, you would use the real group values in the DISCRETEATTRMAP and those values would show up in the legend. If your trying to use group for positive/negative, you can use the terms like "positive" and "negative" in your data and have that appear in the legend. If you want to create a legend that has no connection to the group variable, there is a way in SAS 9.3 to create a custom legend entry that can be associated with a legend instead of your bar chart. Just let me know what you desire in your legend.

View solution in original post

2 REPLIES 2
DanH_sas
SAS Super FREQ

LEGENDLABELs do not work in group variable situation. I'm not sure what you want in your legend. Typically, you would use the real group values in the DISCRETEATTRMAP and those values would show up in the legend. If your trying to use group for positive/negative, you can use the terms like "positive" and "negative" in your data and have that appear in the legend. If you want to create a legend that has no connection to the group variable, there is a way in SAS 9.3 to create a custom legend entry that can be associated with a legend instead of your bar chart. Just let me know what you desire in your legend.

Brigitte_sas
SAS Employee

Hi Dan,

thank you very much for your suggestion!

I change the terms in my data to "positive volume of sale" and "negative volume of sale"  ==> this works fine and I think this will be OK for my customer.

Best regards,

Brigitte

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3122 views
  • 0 likes
  • 2 in conversation