BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
zhangda
Fluorite | Level 6

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;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

5 REPLIES 5
ballardw
Super User

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.

zhangda
Fluorite | Level 6

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;

Reeza
Super User

VBAR Option - categoryorder=respdesc

 

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

 

 

zhangda
Fluorite | Level 6

Thank you so much!

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2913 views
  • 2 likes
  • 3 in conversation