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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.