- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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;