turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS/GRAPH and ODS Graphics
- /
- sgplot vbar data label of sum

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-27-2017 04:32 PM

I am running an sgplot vbar where the stat is the mean and I would like to label each vbar with the sample size in each group. is there a way I can do this, something like datalabel=(stat=sum) [but this does not work].

Accepted Solutions

Solution

10-27-2017
05:13 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Melk

10-27-2017 05:07 PM

I was talking with Sanjay about this one, and he pointed out that another alternative would be to just pre-compute the data in PROC MEANS and use a VBARPARM to render it. Here's what that would look like:

```
proc means data=sashelp.class nway;
class age;
var weight;
output out=temp mean=weight_mean n=weight_n;
run;
proc sgplot data=temp;
vbarparm category=age response=weight_mean / datalabel=weight_n;
run;
```

All Replies

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Melk

10-27-2017 04:44 PM

How about something like this?

```
proc sgplot data=sashelp.class;
vbar age / response=weight stat=mean;
xaxistable weight / stat=freq location=inside
position=top;
run;
```

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to DanH_sas

10-27-2017 04:52 PM - edited 10-27-2017 04:54 PM

I am formatting the response variable as a percent since it is a binary variable, and I want the proportion of 1s (vs 0s). I want the total sample size in each group to be displayed per bar (num of 0s + 1s).

Because of this format I think, when I run with your suggestions it is giving me percentages rather than counts. Am I able to employ 2 different formats for the same variable within a proc block?

proc sgplot data=dat;

vbar days / response=mort stat=mean;

format mort percent6.2;

run;

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Melk

10-27-2017 05:02 PM

What version of SAS are you using?

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to DanH_sas

10-27-2017 05:14 PM

SAS 9.4

Solution

10-27-2017
05:13 PM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Melk

10-27-2017 05:07 PM

I was talking with Sanjay about this one, and he pointed out that another alternative would be to just pre-compute the data in PROC MEANS and use a VBARPARM to render it. Here's what that would look like:

```
proc means data=sashelp.class nway;
class age;
var weight;
output out=temp mean=weight_mean n=weight_n;
run;
proc sgplot data=temp;
vbarparm category=age response=weight_mean / datalabel=weight_n;
run;
```

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to DanH_sas

10-27-2017 05:14 PM

Worked beautifully - much appreciated.