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

I'm trying to create a clustered bar chart where the two bars within each cluster are side by side without space in between. My code is separating the clusters by bar color, but doesn't seem to be doing it spatially. I've tried adjusting both the barwidth and clusterwidth options unsuccessfully. They both seem to be affecting just the bar widths.  I appreciate assistance on getting the display right. My data, code, and results are below. Thanks.

 

 

InstAll pr1 d1 survey
f_pr_score1 25 25.0 Faculty
s_pr_score1 55.66666667 55.7 Student
f_pr_mean1 59.86574737 59.9 Faculty
s_pr_mean1 60.67674272 60.7 Student

 

data temp4;
input install $11. pr1 d1 survey $;
cards;
f_pr_score1 25 25.0 Faculty
s_pr_score1 55.66666667 55.7 Student
f_pr_mean1 59.86574737 59.9 Faculty
s_pr_mean1 60.67674272 60.7 Student
;
run;

 

proc sgplot data=temp4;
title 'A student body that reflects the diversity of society at large';
vbar install / response=pr1 datalabel=d1 barwidth=.25 group=survey groupdisplay=cluster;
yaxis label='Rating';
xaxis values=('f_pr_score1' 'f_pr_mean1' 's_pr_score1' 's_pr_mean1') 
	  valuesdisplay=('Faculty Rating' 'Faculty National Mean' 'Student Rating' 'Student National Mean')
 	  display=(nolabel);
run;

 

 

 

NeilH_3-1721915260370.png

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

I think if you restructure the form of your data, you'll be able to get what you want. Is this the desired output?

data temp4;
input survey $ Source $ pr1 d1 ;
datalines;
Faculty Local    25   25
Student Local    55.6 55.7
Faculty National 59.8 59.9
Student National 60.6 60.7
run;

title 'A student body that reflects the diversity of society at large';
proc sgplot data=temp4;
   vbar Survey / response=pr1 datalabel=d1 group=source groupdisplay=cluster;
   yaxis label='Rating';
   xaxis display=(nolabel);
run;

SGPlot23.png

View solution in original post

4 REPLIES 4
ballardw
Super User

Please post code as text instead of as pictures by copy and pasting into either a text or code box opened on the forum with the </> or "running man" icons that appear above the message window. If we want to make code changes as possible solutions to your question it much easier for us to copy / paste/ edit than to retype everything from scratch.

Similarly data should not be a picture but text and best as working data step to recreate your data set.

 

To get graph like I think you intend the variable Install should have two values, likely Score and Mean. Then both of the scores would appear adjacent and both of the means with the Survey value providing the color.

 

I can't provide an actually working example because pictures and I'm way too lazy to attempt to recreate everything from scratch.

NeilH
Obsidian | Level 7

Thanks for the tip. I edited my post to paste in the code.

Rick_SAS
SAS Super FREQ

I think if you restructure the form of your data, you'll be able to get what you want. Is this the desired output?

data temp4;
input survey $ Source $ pr1 d1 ;
datalines;
Faculty Local    25   25
Student Local    55.6 55.7
Faculty National 59.8 59.9
Student National 60.6 60.7
run;

title 'A student body that reflects the diversity of society at large';
proc sgplot data=temp4;
   vbar Survey / response=pr1 datalabel=d1 group=source groupdisplay=cluster;
   yaxis label='Rating';
   xaxis display=(nolabel);
run;

SGPlot23.png

NeilH
Obsidian | Level 7

Thank you, Rick. That worked!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 519 views
  • 2 likes
  • 3 in conversation