By specifiying "datalabel=percent in the histogram statment of proc sglot/sgpanel, you can get a percentage above each bar. Useful as far as it goes, but the percentages use the best6. format. Is there a way to specify e.g. 8.1 as the format for these percentages?
Here's some sample code:
proc sgplot data=sashelp.class; histogram age / datalabel=percent; run;
Specifying a format for age, percent, or datalabel has no impact. The percentages displayed have values like 42.105 or 5.2632. Is there a way to change this in proc sgplot? I've seen examples on how to do this using proc gplot but that's not what I'm interested in. I'm using SAS 9.4M1/
I can't find anything about a percent variable being created, doesn't mean it doesnt exist though. Anyways from the documentation:
If you leave SAS to decide it will assign best6. so as with anything, do it yourself to make sure:
Have a datatstep before teh sgplot:
data want set sashelp.class; pc=(val / div) * 100; /* or use round */ format pc percent5.2; run; proc sgplot data=want; histogram age / datalabel=pc; run;
@RW9, the OP is asking about the DATALABEL=PERCENT option in the HISTOGRAM statement. PERCENT is a keyword, not a variable. (Yes, this is different than for plots with markers, such as the SCATTER stmt.)
OP: I think the answer is that you cannot control the format of the bar labels from PROC SGPLOT, but perhaps @DanH_sas will prove me wrong.
No, this won't work. The counts and percentages are created by proc sglot and depend on the number of bins. You can specify the nbins option or let SAS determine the number of bins, as was done in my simple example. The counts and percentages aren't available in your input data.
Sorry, I can't find anything on this anywhere (typical trying to search for graph items, can never find anything in the docs) other thn the default is best6. You can try looking through this blog:
It has plenty of examples of pretty much all graphs, but again I couldn't find this option used there either.
Fo rmy graphs I always get the data up front in a dataset then graph from that data rather than using inbuilt functions as its far simpler then to alter data/sort, group etc exactly as I want.
Using this code you can get the Y axis to display in percent, I do not know of a way to display the label at the top of the bar.
proc sgplot data=sashelp.class; histogram age / scale=proportion datalabel=percent; yaxis display=(nolabel) valuesformat=percent9.2; run;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.