Data visualization with SAS programming

gplot: displaying missing categories as 0

Reply
Regular Contributor
Posts: 195

gplot: displaying missing categories as 0

I have data that looks like this:
month count
1 10
2 20
4 19
5 5

How do I plot month=3 as count=0?

Thank you.
Super Contributor
Posts: 291

Re: gplot: displaying missing categories as 0

data test;
input month count ;
cards;
1 10
2 20
3 0
4 19
5 5
;
goptions dev=win;
proc gchart;
vbar month/sumvar=count
discrete

;
run;
SAS Employee
Posts: 967

Re: gplot: displaying missing categories as 0

Or, without inserting data, you could use a gplot needle plot (which used a proportional axis, rather than only plotting bars for the points you have data at), such as ...

data test;
input month count ;
cards;
1 10
2 20
4 19
5 5
;

symbol1 value=none interpol=needle width=15;
axis1 order=(1 to 5 by 1) minor=none offset=(5,5);
axis2 order=(0 to 25 by 5) minor=none offset=(0,0);
proc gplot data=test;
plot count*month=1 / haxis=axis1 vaxis=axis2;
run;
Regular Contributor
Posts: 195

Re: gplot: displaying missing categories as 0

This looks good.
Is it possible to use lines instead of bars?
Thank you.
SAS Employee
Posts: 967

Re: gplot: displaying missing categories as 0

Certainly! - That would be the very basic line plots - described in more detail in the doc - you've checked there first, right? :-)


All you'd have to do is modify the symbol statement in the above example, as follows:

data test;
input month count ;
cards;
1 10
2 20
4 19
5 5
;

symbol1 value=dot height=2 interpol=join;
axis1 order=(1 to 5 by 1) minor=none offset=(5,5);
axis2 order=(0 to 25 by 5) minor=none offset=(0,0);
proc gplot data=test;
plot count*month=1 / haxis=axis1 vaxis=axis2;
run;


Or, if you want to have a "gap" in the line plot, where the value at 3 is missing, then insert a SAS "missing value" in the data, and use the 'skipmiss' gplot option...

data test;
input month count ;
cards;
1 10
2 20
3 .
4 19
5 5
;

symbol1 value=dot height=2 interpol=join;
axis1 order=(1 to 5 by 1) minor=none offset=(5,5);
axis2 order=(0 to 25 by 5) minor=none offset=(0,0);
proc gplot data=test;
plot count*month=1 / haxis=axis1 vaxis=axis2 skipmiss;
run;
proc print data=test; run;
Regular Contributor
Posts: 195

Re: gplot: displaying missing categories as 0

I liked how the needle plot reflected count=0.
I was hoping there was a better way to reflect count=0 with the line plot (ie the line actually goes down to 0 instead of just not display a dot).
SAS Employee
Posts: 967

Re: gplot: displaying missing categories as 0

To do that, you'd have to insert a zero value into the data...

data test;
input month count ;
cards;
1 10
2 20
3 0
4 19
5 5
;

symbol1 value=dot height=2 interpol=join;
axis1 order=(1 to 5 by 1) minor=none offset=(5,5);
axis2 order=(0 to 25 by 5) minor=none offset=(0,0);
proc gplot data=test;
plot count*month=1 / haxis=axis1 vaxis=axis2;
run;
Ask a Question
Discussion stats
  • 6 replies
  • 212 views
  • 0 likes
  • 3 in conversation