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

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.

Screenshot 2021-03-16 at 16.01.55.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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

View solution in original post

4 REPLIES 4
DanH_sas
SAS Super FREQ

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

marta25
Obsidian | Level 7

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?

Screenshot 2021-03-18 at 22.24.35.png

DanH_sas
SAS Super FREQ

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.

marta25
Obsidian | Level 7
Great! Thank you so much @Dan!!! 🙂

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
  • 4 replies
  • 1114 views
  • 3 likes
  • 2 in conversation