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
@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;
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;
@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;
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!
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.