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

I am trying to create a vertical bar using a data set. The chart compares the mean GPA by gender for medium-sized schools. I used below code:

 

title h=14pt "GPA by Gender";

proc sgplot data=BAS150.College;
vbar Gender / response=GPA stat=mean datalabel datalabelattrs=(size=14pt);
xaxis label="Gender" labelattrs=(size=14pt);
yaxis label="Mean GPA" labelattrs=(size=14pt);

run;

The output gives the GPA of all school size. PS SchoolSize variable have Large, Medium and Small categories. 

How do I add group?

if I add group :

 

title h=14pt "GPA by Gender";

proc sgplot data=BAS150.College;
vbar Gender / response=GPA stat=mean datalabel datalabelattrs=(size=14pt)
group= SchoolSize;
xaxis label="Gender" labelattrs=(size=14pt);
yaxis label="Mean GPA" labelattrs=(size=14pt);

run;

then output is all the group of schoolsize in that vbar.

 

How can I filter schoolsize to medium and then plot the graph?

please help

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@vedaj16 wrote:

The output gives the GPA of all school size. PS SchoolSize variable have Large, Medium and Small categories. 

How do I add group?

if I add group :

 

title h=14pt "GPA by Gender";

proc sgplot data=BAS150.College;
vbar Gender / response=GPA stat=mean datalabel datalabelattrs=(size=14pt)
group= SchoolSize;
xaxis label="Gender" labelattrs=(size=14pt);
yaxis label="Mean GPA" labelattrs=(size=14pt);

run;

then output is all the group of schoolsize in that vbar.

 


By default the Vbar Group= option with create a vertical stack of the group values. If you want a single bar for each group add:

Groupdisplay = Cluster to override the default Groupdisplay =Stack.

title h=14pt "GPA by Gender";

proc sgplot data=BAS150.College;
   vbar Gender / response=GPA stat=mean datalabel datalabelattrs=(size=14pt)
       group= SchoolSize groupdisplay=cluster;
   xaxis label="Gender" labelattrs=(size=14pt);
   yaxis label="Mean GPA" labelattrs=(size=14pt);

run;

View solution in original post

2 REPLIES 2
vedaj16
Calcite | Level 5

My bad 😞

I put medium instead of M 

My where statement worked not 🙂

 

title h=14pt "GPA by Gender of Medium Size School";

proc sgplot data=BAS150.COLLEGE (where =(SchoolSize = 'M'));
vbar Gender / response=GPA stat=mean datalabel datalabelattrs=(size=14pt)
;
xaxis label="Gender" labelattrs=(size=14pt);
yaxis label="Mean GPA" labelattrs=(size=14pt);

run;

 

ballardw
Super User

@vedaj16 wrote:

The output gives the GPA of all school size. PS SchoolSize variable have Large, Medium and Small categories. 

How do I add group?

if I add group :

 

title h=14pt "GPA by Gender";

proc sgplot data=BAS150.College;
vbar Gender / response=GPA stat=mean datalabel datalabelattrs=(size=14pt)
group= SchoolSize;
xaxis label="Gender" labelattrs=(size=14pt);
yaxis label="Mean GPA" labelattrs=(size=14pt);

run;

then output is all the group of schoolsize in that vbar.

 


By default the Vbar Group= option with create a vertical stack of the group values. If you want a single bar for each group add:

Groupdisplay = Cluster to override the default Groupdisplay =Stack.

title h=14pt "GPA by Gender";

proc sgplot data=BAS150.College;
   vbar Gender / response=GPA stat=mean datalabel datalabelattrs=(size=14pt)
       group= SchoolSize groupdisplay=cluster;
   xaxis label="Gender" labelattrs=(size=14pt);
   yaxis label="Mean GPA" labelattrs=(size=14pt);

run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 2 replies
  • 1254 views
  • 0 likes
  • 2 in conversation