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;
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;
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;
Thank you, @Rick_SAS
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.