BookmarkSubscribeRSS Feed
vsl2000
Calcite | Level 5

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;

ExQbyV.pngExQbyG.png

7 REPLIES 7
Reeza
Super User

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;

ExQbyV.pngExQbyG.png


 

vsl2000
Calcite | Level 5

 

Exprocfreq.png

 

Reeza
Super User

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:

 

Exprocfreq.png

 


 

vsl2000
Calcite | Level 5

I'm hoping to group the chart by vermont=1 and vermont=. so that each bar has 2 colors

Reeza
Super User

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. 

 

Tom
Super User Tom
Super User

Perhaps the 119 in your data is really 119 +/- some small value?

ballardw
Super User

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;

sas-innovate-2024.png

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.

 

Register now!

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
  • 7 replies
  • 1608 views
  • 0 likes
  • 4 in conversation