Data visualization with SAS programming

How to draw a bar line chart?

Accepted Solution Solved
Reply
Contributor
Posts: 74
Accepted Solution

How to draw a bar line chart?

Hello!

 

I have data as below, from which I want to draw a bar-line chart, volume is the bar and rate is the line, would you please help me?

Thanks!

 


data test;
input
Type $2. Volume 5. Rate 18.;
cards;
A -105 0
B -102 -0.005839013
C -97 0.039130435
D -91 -0.002736612
E -78 0
F -67 0
G -58 -0.166469762
H -55 0.058062447
I -52 0
J -34 0.101676241
K -30 -0.035087719
L -27 -0.001283148
M -25 -0.147058824
N -21 0.001364522
O -21 -0.019047619
P -19 -0.033603803
Q -18 0
R -12 0
S -12 0
T -12 0.338461539
U -11 0.155289702
V -10 0
W -10 -0.255411255
X -8 0
Y -7 0
Z -7 0.02945253
;run;


Accepted Solutions
Solution
‎03-08-2017 02:16 PM
Grand Advisor
Posts: 9,681

Re: How to draw a bar line chart?

Here is one approach:

proc sgplot data=test;
   vbar type / response=volume stat=sum;
   vline type/ response=rate y2axis;
run;

SGPLOT will attempt to overlay each separate plot type. However there are severe restrictions of what may be combined.

 

The Y2axis is needed because the range of values you have for rate is so small that it gets buried in the base of the bars.

Look in the documentation for SGPLOT for axis and other appearance options.

View solution in original post


All Replies
Solution
‎03-08-2017 02:16 PM
Grand Advisor
Posts: 9,681

Re: How to draw a bar line chart?

Here is one approach:

proc sgplot data=test;
   vbar type / response=volume stat=sum;
   vline type/ response=rate y2axis;
run;

SGPLOT will attempt to overlay each separate plot type. However there are severe restrictions of what may be combined.

 

The Y2axis is needed because the range of values you have for rate is so small that it gets buried in the base of the bars.

Look in the documentation for SGPLOT for axis and other appearance options.

Contributor
Posts: 74

Re: How to draw a bar line chart?

Hi Ballard,

 

Would you please guide me how to put the bars in a descending  order(from the highest to lowest height),  I sorted it before sgplot but why the bars still show disorderly? (see the data below). Thanks a lot!

 

 

data test;
input
Type $2. Volume 5. Rate 18.;
cards;
A -19 0
B -102 -0.005839013
C -97 0.039130435
D -91 -0.002736612
E -78 0
F -6 0
G -58 -0.166469762
H -55 0.058062447
I -52 0
J -34 0.101676241
K -30 -0.035087719
L -27 -0.001283148
M -25 -0.147058824
N -2 0.001364522
O -21 -0.019047619
P -19 -0.033603803
Q -18 0
R 12 0
S -12 0
T 11 0.338461539
U -11 0.155289702
V -10 0
W -10 -0.255411255
X -8 0
Y 24 0
Z -7 0.02945253
;run;

proc sort data=test output=test2;by descending volume ;run;
ods graphics / width=15in height=6.81in;
proc sgplot data=test2;
vbar type / response=volume stat=sum;
vline type/ response=rate y2axis;
run;

Grand Advisor
Posts: 16,262

Re: How to draw a bar line chart?

VBAR Option - categoryorder=respdesc

 

vbar type / response=volume stat=sum categoryorder=respdesc;

 

 

Contributor
Posts: 74

Re: How to draw a bar line chart?

Thank you so much!

Grand Advisor
Posts: 16,262
Post a Question
Discussion Stats
  • 5 replies
  • 95 views
  • 2 likes
  • 3 in conversation