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

hi there

 

i am creating a scatter plot and i want to add the actual values on each bar.

My code:

proc sgplot data = consolidated;

vbar channel/group = subchannel groupdisplay = stack;

run;

 

how do i get the values to show on the bars?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Have you tried the SEGLABEL option on the VBAR statement? That should add labels to each section which I think is what you are asking. If you also want the bar "total" value then DATALABEL would also be needed.

View solution in original post

3 REPLIES 3
ballardw
Super User

Have you tried the SEGLABEL option on the VBAR statement? That should add labels to each section which I think is what you are asking. If you also want the bar "total" value then DATALABEL would also be needed.

Citrine10
Obsidian | Level 7

Thank you. that solved it 🙂

 

how do i show the label on a stack thats really small though? 

ballardw
Super User

@Citrine10 wrote:

Thank you. that solved it 🙂

 

how do i show the label on a stack thats really small though? 


Depending on the actual data and how important it may be to show something like 0.01% (just an example) there are a few options that may work.

 

Make the graph physically taller (or wider for HBAR), the ODS GRAPHICS option lets you control the height/width of the graph display area. This probably most useful if the text almost fits.

 

The SEGLABELATTRS can modify text size of the labels so a smaller or different font may work. Again more likely if the current text almost fits.

 

For extremely small values it may be better to create a custom format for the variable that would suppress text , show a "blank" value for very small ranges. That at least keeps from getting collisions and hard to read text.

 

If you "know" that several group values are consistently extremely small individually create a group value that represents 2 or more categories and provide an appropriate group definition. This may make more sense if the "groups" represent some sort of order that naturally places them together.

 

You can create an annotate data set and use the SGANNO option on the Proc statement to use the set. This is a bit of work as then you have to provide coordinates for where you actually want text to appear as well as the text. Sometimes with VBAR and character axis values this can be a challenge. I would use this in conjunction with the custom format suppressing the small values on the bar and then just display the value off to the side of the bar.

Related to this is using the VBARBASIC, to allow sharing with other types of charts and modify you existing data to include some additional values/variables to do a TEXT plot overlaying the graph with the label values. Again this might be just the "small" values. Both of these overlay approaches often work better with summarized values instead of letting VBAR build the heights using the internal stats.

 

Sometimes vertical scales might work such as a Log scale for the Yaxis but that only helps if the "small" values to display are actually appearing at the base of the bar.

 

Unless there is a lot of $$$ involved for the exact values of the small segments I tend to suppress the values on the actual bar and then use a footnote or other explanatory text that indicates the range of values that were suppressed.

 

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2420 views
  • 1 like
  • 2 in conversation