BookmarkSubscribeRSS Feed
salexgray
Calcite | Level 5

Hi everyone, 

 

I apologize if this topic has been covered before, I searched through previous posts with no luck.

 

I'm having trouble changing the number of decimal places shown on the column data labels for my histogram. Currently, 3 decimals places are shown for each column, resulting in some visual overcrowding. I hope to reduce this to only 1 decimal place. 

 

When consulting the SAS help center, the suggested syntax is to use PCTNDEC=1 with STAT=percent, however STAT=percent is not being recognized in my code, and the PCTNDEC code is not working by itself.

 

Code:

proc sgplot data=my.drc pctndec=1;
histogram I_BENPCK2 /datalabel=Percent;
xaxis label='Extent of Benefit' values=(20 40 60 78 100);
dropline x=78 y=31 / dropto=x lineattrs=(color=red);
run;

 

Thank you! 

 

2 REPLIES 2
Rick_SAS
SAS Super FREQ

That's a good question. I don't know a simple answer. I can tell you that the PCTNDEC= option is not for histograms. It is mostly used for stacked bar charts. 

 

A workaround might be to use the GRID option on the YAXIS statement to add horizontal reference lines. The viewer can estimate the percentages by eye:

yaxis grid values=(0 to 100 by 5) valueshint;

ballardw
Super User

Personally, I would create my own groups of the x-axis variable, summarize the data such as with proc freq to get count and percentage variables and then use VBAR. That way I can easily control the datalabels with a format.

 

Going back more than 25 years and Proc GCHART, almost every attempt to use a graphic procedure calculated percentage left some problem if trying to create publication quality graphs, such as this format of displayed labels, that has no easy solution. So creating the actual values needed in a data set would usually let me have a value to display.

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2041 views
  • 2 likes
  • 3 in conversation