Graphics Programming

Data visualization using SAS programming, including ODS Graphics and SAS/GRAPH. Charts, plots, maps, and more!
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Melk
Lapis Lazuli | Level 10

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].

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

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;

 

View solution in original post

6 REPLIES 6
DanH_sas
SAS Super FREQ

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;
Melk
Lapis Lazuli | Level 10

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;

DanH_sas
SAS Super FREQ

What version of SAS are you using?

Melk
Lapis Lazuli | Level 10

SAS 9.4

DanH_sas
SAS Super FREQ

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;

 

Melk
Lapis Lazuli | Level 10

Worked beautifully - much appreciated.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 6 replies
  • 6003 views
  • 1 like
  • 2 in conversation