SAS Programming

DATA Step, Macro, Functions and more
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-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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