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

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_NameMedalCount
ChinaGold38
ChinaSilver28
ChinaBronze22
GBGold29
GBSilver17
GBBronze19
USGold46
USSilver28
USBronze29

 

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!

 

 

Bar Chart.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

On the PANELBY statement, use SORT=DATA:

 

panelby Medal / layout=columnlattice onepanel sort=data ...

View solution in original post

2 REPLIES 2
Rick_SAS
SAS Super FREQ

On the PANELBY statement, use SORT=DATA:

 

panelby Medal / layout=columnlattice onepanel sort=data ...

GraphGuy
Meteorite | Level 14

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;

medals2.png

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 717 views
  • 1 like
  • 3 in conversation