BookmarkSubscribeRSS Feed
gzr2mz39
Quartz | Level 8
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.
6 REPLIES 6
Bill
Quartz | Level 8
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;
GraphGuy
Meteorite | Level 14
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;
gzr2mz39
Quartz | Level 8
This looks good.
Is it possible to use lines instead of bars?
Thank you.
GraphGuy
Meteorite | Level 14
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;
gzr2mz39
Quartz | Level 8
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).
GraphGuy
Meteorite | Level 14
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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 6 replies
  • 1302 views
  • 0 likes
  • 3 in conversation