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