Hi!
I am trying to get a bar chart that shows me the number of gold silver and bronze medals by three countries.
My dataset currently looks like this:
Country_Name | Medal | Count |
China | Gold | 38 |
China | Silver | 28 |
China | Bronze | 22 |
GB | Gold | 29 |
GB | Silver | 17 |
GB | Bronze | 19 |
US | Gold | 46 |
US | Silver | 28 |
US | Bronze | 29 |
My code is:
proc sgpanel data= medal;
panelby Medal / layout=columnlattice onepanel sort = (descformat)
colheaderpos=bottom rows=1 novarname noborder;
vbar Country_Name / group=Country_Name response=count stat=sum group=Country_Name nostatlabel;
colaxis display= none;
rowaxis grid;
run;
This code works and I have attached the output to this message. However, i need my chart to show Gold, Silver, then Bronze. Right now, it shows Silver, Gold, Bronze. Any help on this would be appreciated!
Also is there a way to do this using proc gchart? My code for it doesn't seem to be working:
PROC GCHART DATA=medal;
VBAR Country_Name/GROUP=medal subgroup = Country_Name; *MAXIS=AXIS1 AXIS=AXIS2;
RUN;
QUIT;
Thank you!
On the PANELBY statement, use SORT=DATA:
panelby Medal / layout=columnlattice onepanel sort=data ...
On the PANELBY statement, use SORT=DATA:
panelby Medal / layout=columnlattice onepanel sort=data ...
Here's one way to do it with SAS/Graph Gchart:
data medal;
length Country_Name Medal $10;
input Country_Name Medal Count;
datalines;
China Gold 38
China Silver 28
China Bronze 22
GB Gold 29
GB Silver 17
GB Bronze 19
US Gold 46
US Silver 28
US Bronze 29
;
run;
axis1 label=none label=none major=none minor=none style=0;
axis2 label=none offset=(3pct,3pct) order=('Gold' 'Silver' 'Bronze');
axis3 label=none;
title "Medal Count";
proc gchart data=medal;
vbar country_name / group=medal subgroup=country_name sumvar=count
space=0 nolegend raxis=axis1 gaxis=axis2 maxis=axis3 noframe
autoref clipref cref=gray77 lref=33;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.