BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dustychair
Pyrite | Level 9

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;

SGPlot61.png

SGPlot64.png

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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;

View solution in original post

3 REPLIES 3
svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10
Hello,

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...
Rick_SAS
SAS Super FREQ

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;
dustychair
Pyrite | Level 9

Thank you, @Rick_SAS 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2826 views
  • 0 likes
  • 3 in conversation