turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS/GRAPH and ODS Graphics
- /
- How to draw a bar line chart?

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-08-2017 01:28 PM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to zhangda

03-08-2017 02:00 PM

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.

All Replies

Solution

03-08-2017
02:16 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to zhangda

03-08-2017 02:00 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ballardw

03-08-2017 03:29 PM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to zhangda

03-08-2017 03:35 PM

VBAR Option - categoryorder=respdesc

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

03-08-2017 03:39 PM

Thank you so much!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to zhangda

03-08-2017 02:14 PM

What version of SAS do you have?

Top 3 hits from Google : SAS Bar Line Chart

http://support.sas.com/rnd/datavisualization/yourGraphs/businessQuick/barline/

http://blogs.sas.com/content/graphicallyspeaking/2012/04/02/bar-line-graph/