BookmarkSubscribeRSS Feed
FloB
Calcite | Level 5

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.

FloB_0-1614164637601.png

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

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

Like this?

 

proc sgplot data=tempo pctlevel=group ;
hbar codetrt / response=allpat group=score stat=freq seglabel freq=nbpat;
run;

 

Result:

 

 

Udklip.PNG

 

 

FloB
Calcite | Level 5
Not quite...

As in the same time, I want the cumulative percent to add-up to 100% in each group, and get the cumulative percent on the x-axis.

Rick_SAS
SAS Super FREQ

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.

FloB
Calcite | Level 5

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

ballardw
Super User

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

FloB
Calcite | Level 5
Thank you all for considering my request.


I finally managed to get what I wanted with the sganno= option and the annotate facilities using a table from a previous PROC FREQ

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is ANOVA?

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.

Discussion stats
  • 6 replies
  • 914 views
  • 2 likes
  • 4 in conversation