DATA Step, Macro, Functions and more

proc format cannot format null value

Reply
Occasional Contributor
Posts: 6

proc format cannot format null value

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

Super User
Posts: 24,015

Re: proc format cannot format null value

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


 

Occasional Contributor
Posts: 6

Re: proc format cannot format null value

 

Exprocfreq.png

 

Super User
Posts: 24,015

Re: proc format cannot format null value

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

 


 

Occasional Contributor
Posts: 6

Re: proc format cannot format null value

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

Super User
Posts: 24,015

Re: proc format cannot format null value

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. 

 

Super User
Super User
Posts: 8,281

Re: proc format cannot format null value

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

Super User
Posts: 13,941

Re: proc format cannot format null 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;

Ask a Question
Discussion stats
  • 7 replies
  • 152 views
  • 0 likes
  • 4 in conversation