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