I am trying to group bars in a vbar chart.
The group variable vermont is either 1 or .
I have included a plot grouped by gender to show that it works with that variable, but not vermont
here is my code:
data survey;
set mylib.thesisdata2;
run;
proc format;
value typev
1='Vermont'
.='New Hampshire'
0='New Hampshire';
run;
proc format;
value typeedu
119='Did not graduate high school'
120='High school graduate/GED'
121='Some college education'
122='4-year college degree'
123='Graduate degree';
proc format;
value typegender
117='Male'
118='Female';
run;
proc sgplot data=Survey;
format EDUCATIO typeedu.;
format VERMONT typev.;
vbar EDUCATIO/group=VERMONT;
title 'What is the highest level of education you have completed?';
run;
proc sgplot data=Survey;
format EDUCATIO typeedu.;
format GENDER typegender.;
vbar EDUCATIO/group=GENDER;
title 'What is the highest level of education you have completed?';
run;
It looks like you don't have the value in your data set.
Run both of these and post the results please:
proc freq data=survey;
table vermont;
format vermont;
run;
proc freq data=survey;
table vermont;
format vermont typev.;
run;
@vsl2000 wrote:
I am trying to group bars in a vbar chart.
The group variable vermont is either 1 or .
I have included a plot grouped by gender to show that it works with that variable, but not vermont
here is my code:
data survey;
set mylib.thesisdata2;
run;
proc format;
value typev
1='Vermont'
.='New Hampshire'
0='New Hampshire';
run;
proc format;
value typeedu
119='Did not graduate high school'
120='High school graduate/GED'
121='Some college education'
122='4-year college degree'
123='Graduate degree';
proc format;
value typegender
117='Male'
118='Female';
run;
proc sgplot data=Survey;
format EDUCATIO typeedu.;
format VERMONT typev.;
vbar EDUCATIO/group=VERMONT;
title 'What is the highest level of education you have completed?';
run;
proc sgplot data=Survey;
format EDUCATIO typeedu.;
format GENDER typegender.;
vbar EDUCATIO/group=GENDER;
title 'What is the highest level of education you have completed?';
run;
Well, you only have 2 value, a 1 or . for VERMONT, so you're getting exactly what I'd expect to see based on your code.
What are you expecting that's not happening?
@vsl2000 wrote:
I'm hoping to group the chart by vermont=1 and vermont=. so that each bar has 2 colors
Both . and 1 are assigned to Vermont which means they're grouped together.
Call the missing one Vermont - Missing or something else and see if that works for you.
Perhaps the 119 in your data is really 119 +/- some small value?
The GROUP variable cannot have missing values if you want information to display in a group. Take a pass through a data step and change:
if Vermont=. then Vermont=0;
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.