Hi,
I'd like to display on a single plot using vbar or similar labeling with both percentage and frequency count displayed. I use sas 9.4.
Code I have is:
proc sgplot data=have noborder;
yaxis label= "Counts";
vbar var/GROUPORDER=ascending stat=percent datalabel;
run;
How can I modify it to add counts?
Thanks.
See if this will work for you:
proc sgplot data=sashelp.class noborder;
yaxis label= "Counts";
vbar age/GROUPORDER=ascending stat=percent datalabel;
xaxistable age / location=inside stat=freq;
run;
Hope this helps!
Dan
I get the percent labels on the bars and the freq values in the axis table. What version of SAS 9.4 do you have? Please run this and let me know what the log says:
%put &sysvlong;
Thanks!
Dan
In the example, the freq values are along the bottom of the bars. I get this with 9.4m3 as well: They can be also moved to the top of the graph.
In that case, just add LABEL="Frequency" to the XAXISTABLE statement (after the "/").
Or, are you saying that it just repeats 11, 12 13, 14, 15, and 16?
Try this and see if it works for you:
In a small datastep, copy your category column to another column (such as age2, in this example.) Use age2 in the XAXISTABLE instead.
data class;
set sashelp.class;
age2=age;
run;
proc sgplot data=sashelp.class noborder;
yaxis label= "Counts";
vbar age/GROUPORDER=ascending stat=percent datalabel;
xaxistable age2 / location=inside stat=freq label="Frequency";
run;
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.
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.
Ready to level-up your skills? Choose your own adventure.