Dear all,
I am trying to get a hbar graph using sgplot to represent the relative contribution of scores (0 to 3) in 2 groups.
I used the following code:
data tempo;
input codetrt score nbpat;
allpat=1;
cards;
1 0 12
1 1 8
1 2 5
1 3 8
2 0 5
2 1 6
2 2 9
2 3 15
run;
proc sgplot data=tempo pctlevel=group ;
hbar codetrt / response=allpat group=score stat=percent seglabel freq=nbpat;
run;
I would like to get the frequency counts instead of percentages inside each segment.
Could anyone help?
Thanks
Like this?
proc sgplot data=tempo pctlevel=group ;
hbar codetrt / response=allpat group=score stat=freq seglabel freq=nbpat;
run;
Result:
See the article "Construct a stacked bar chart in SAS where each bar equals 100%", which includes code for PROC SGPLOT. The article does not use the SEGLEVEL option, but I think you already know how to do that.
Thank you for the reference, but I have no problem to produce a 100% stacked bar plot.
The only thing I want to change from the graph I posted is to get the freqencies instead of the percentages displayed inside the segments of the bars
@FloB wrote:
Thank you for the reference, but I have no problem to produce a 100% stacked bar plot.
The only thing I want to change from the graph I posted is to get the freqencies instead of the percentages displayed inside the segments of the bars
I suspect you'll have to summarize the data before plotting so you have a variable containing the frequency that can be used to display with a DATALABEL=<freqvar> if you are going to plot percentages.
Going back to the days of GCHART in SAS 6 almost never used the stat= approach to create graphs because I almost always wanted/needed something that was not available. So I would summarize the data to have all the values I needed and control the plot.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.