- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I am using below code to draw a bar graph. The total percentage of all groups in the graph is 100%. However I want to get 100% for each group. For example, the total of "5.sinif" should be 100%, the total of "6.sinif" should be 100%. pctlevel statement did not resolve my question. The second graph was populated when I used pctlevel=group.
Also, "sinif" below the x category in the graph is not sorted. How can I sort it?
Thank you
proc sgplot data=ss;
where sinif<9;
vbar _3_Ogretmen_Ogrenci/group=sinif stat=percent datalabel groupdisplay=cluster;
xaxis label= "3.Ogretmen-ogrenci";
yaxis label= "Yuzde";
run;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I like to use PROC FREQ to create the statistics, then use PROC SGPLOT to visualize the bars. For examples and code, see this article on 100% bar charts. The article focuses on STACKED bar charts, so the example use GROUPDISPLAY=STACK. However, you want CLUSTERED bar charts, so modify the examples to use GROUPDISPLAY=CLUSTER. For example, here is the modification of the first example in the article:
proc sort data=sashelp.cars(where=(Type^="Hybrid")) out=cars;
by Origin; /* sort X categories */
run;
proc freq data=cars noprint;
by Origin; /* X categories on BY statement */
tables Type / out=FreqOut; /* Y (stacked groups) on TABLES statement */
run;
title "100% Stacked Bar Chart";
proc sgplot data=FreqOut;
vbar Origin / response=Percent group=Type groupdisplay=cluster;
xaxis discreteorder=data;
yaxis grid values=(0 to 100 by 10) label="Percentage of Total with Group";
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I think you want to add a PCTLEVEL=GROUP option to your SGPLOT statement. The PCTLEVEL= option tells the procedure the level at which the percentages need to add up to 100.
https://documentation.sas.com/doc/en/vdmmlcdc/8.1/grstatproc/p073bl97jzadkmn15lhq58yiy2uh.htm#p0gsg1...
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I like to use PROC FREQ to create the statistics, then use PROC SGPLOT to visualize the bars. For examples and code, see this article on 100% bar charts. The article focuses on STACKED bar charts, so the example use GROUPDISPLAY=STACK. However, you want CLUSTERED bar charts, so modify the examples to use GROUPDISPLAY=CLUSTER. For example, here is the modification of the first example in the article:
proc sort data=sashelp.cars(where=(Type^="Hybrid")) out=cars;
by Origin; /* sort X categories */
run;
proc freq data=cars noprint;
by Origin; /* X categories on BY statement */
tables Type / out=FreqOut; /* Y (stacked groups) on TABLES statement */
run;
title "100% Stacked Bar Chart";
proc sgplot data=FreqOut;
vbar Origin / response=Percent group=Type groupdisplay=cluster;
xaxis discreteorder=data;
yaxis grid values=(0 to 100 by 10) label="Percentage of Total with Group";
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, @Rick_SAS