BookmarkSubscribeRSS Feed
onpoint1
Calcite | Level 5

Is there a command to put data labels in each bar of a chart?  This is what I have:

    proc sgplot data=figure2;
   yaxis label=' ' discreteorder=data valueATTRS=(family='calibri' size=8pt style=normal);
   xaxis discreteorder=data label = ' ' valueATTRS=(family='calibri' size=8pt style=normal);
   vbar group / response = col1 group = name grouporder=data barwidth=0.4 datalabel=col1 datalabelpos=data;
   keylegend / noborder location=outside position=top across=2 valueATTRS=(family='calibri' size=7pt style=normal);
   run;

Using this code gives me the value from the first segment of the stacked bar, at the top of the bar.  Using datalabel by itself gives the grand total at the top.

I need each segment to have it's own label, and some segments are too small for the value, so it would need to be off to the side.  Is there a way to do this?

Thanks


barchart_sample.JPG
2 REPLIES 2
onpoint1
Calcite | Level 5

This doesn't do what the bosses requested, but at least the data is available on the chart:

proc sgplot data=figure2;

            yaxis label=' ' discreteorder=data valueattrs=(family='calibri' size=8pt style=normal) ;

            xaxis discreteorder=data label = ' ' valueattrs=(family='calibri' size=8pt style=normal) ;

            vbar group / response = col1 group = name grouporder=data barwidth=0.4 datalabel=col1 datalabelpos=bottom

                datalabelattrs=(family='calibri' size=6pt style=normal);

            keylegend / noborder location=outside position=top across=2 valueattrs=(family='calibri' size=7pt style=normal);

        run;

It seems logical from the documentation that the datalabelpos=data option should label the data sections, it just doesn't.  I've seen other similar questions on various Communities boards but no easy answers.  Is Annotate the only option?  If anyone knows a great simple solution, I'd still like to see it.

Jay54
Meteorite | Level 14

There are ways to do this, but not by using a simple option on VBAR or VBARPARM.  Sort the values by category and group, and compute the low, high values (and midpoint) for each bar segment per category yourself.  Then, use a HIGHLOW bar to draw the segments.  Use a SCATTER plot with MARKERCHAR to place the values at the midpoint of each segment.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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