Hello,
I am trying to show data labels on the bar chart like in the image.
My code looks like:
proc sgplot data=mydata
styleattrs datacolors=(blue red) datalinepatterns=(solid);
vbar season_ / response=quantity
group=condition limitstat=stderr numstd=1 stat=mean
datalabel=quantity datalabelattrs=(size=12pt) datalabelpos=bottom
limitattrs=(color=black thickness=1) dataskin=pressed attrid=condition groupdisplay=cluster;
.....
I would like to change the label "Ev (mean)" to another name I choose (for example just "mean"), does someone know if there is a way to do it?
Thanks.
Since you need more control, use the XAXISTABLE statement instead of the DATALABEL option to display your values. The code would look something like the following:
proc sgplot data=mydata styleattrs datacolors=(blue red) datalinepatterns=(solid); vbar season_ / response=quantity group=condition limitstat=stderr numstd=1 stat=mean limitattrs=(color=black thickness=1) dataskin=pressed attrid=condition groupdisplay=cluster; xaxistable quantity / stat=mean valueattrs=(size=12pt) location=inside class=condition classdisplay=cluster label="Mean"; .....
There are additional option in the XAXISTABLE statement you might like. See the documentation for more details.
Hope this helps!
Dan
Since you need more control, use the XAXISTABLE statement instead of the DATALABEL option to display your values. The code would look something like the following:
proc sgplot data=mydata styleattrs datacolors=(blue red) datalinepatterns=(solid); vbar season_ / response=quantity group=condition limitstat=stderr numstd=1 stat=mean limitattrs=(color=black thickness=1) dataskin=pressed attrid=condition groupdisplay=cluster; xaxistable quantity / stat=mean valueattrs=(size=12pt) location=inside class=condition classdisplay=cluster label="Mean"; .....
There are additional option in the XAXISTABLE statement you might like. See the documentation for more details.
Hope this helps!
Dan
This is great, thank you for your help @DanH_sas !
Now I have another question: supposing I want to show also the frequency as a statistic, here is the code:
xaxistable quantity / stat=mean valueattrs=(size=12pt) location=inside position=bottom
class=condition classdisplay=cluster label="Mean" labelattrs=(size=12pt);
xaxistable quantity / stat=freq valueattrs=(size=12pt) location=inside position=bottom
class=condition classdisplay=cluster label="N" labelattrs=(size=12pt);
Now the frequency (which I call N) has two decimal values (see screenshot). Do you know if there is a way to change the format, for instance to an integer with 0 decimal values?
The axis table is probably picking up the format from the "quantity" variable. You can work around this issue by using a little data step to copy the values from "quantity" to "quantity2" and setting a BEST. format on "quantity2". Then, use the "quantity2" variable for the FREQ axis table.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.