Data visualization with SAS programming

Plotting two variables on one graph

Reply
New Contributor
Posts: 3

Plotting two variables on one graph

I'm looking to plot two separate variables on the same bar graph. I am currently using proc gbarline to plot one of the variables, but I'd like another to be displayed next to it as another bar (not a line - essentially another "sumvar" statement).  Is this possible, or is there another way/procedure that will perform this?  Thanks!

New Contributor
Posts: 3

Plotting two variables on one graph

FYI - The data is complicated enough that I am also plotting by subgroups and it cannot be transposed to create just one variable to graph.

SAS Super FREQ
Posts: 1,044

Plotting two variables on one graph

If you have SAS 9.2 or higher, you can do this using GTL.  Here is an example from a previous post.  Please post your graph and data so I can send you something closer to what you want.

BarLineLegendGTL.png

SAS Employee
Posts: 963

Plotting two variables on one graph

Gbarline supports subgrouped bars (stacked segments), but not grouped bars (side-by-side).

One possible work-around is to use Gchart to create the bar chart, and then use annotate

to draw the line.  Here's an example:

http://robslink.com/SAS/democd29/barline.htm

http://robslink.com/SAS/democd29/barline_info.htm

New Contributor
Posts: 3

Plotting two variables on one graph

Thank you for the information, but it's not quite what I'm looking for.  I'm not actually wanting to put a line on the bar graph, I'm wanting to just make a bar graph that looks like the one you just posted (without the line) - but with two different variables.  I do not have a "type" that both the variables I want to plot are under; they are each their own and must be plotted separately.  Because I also need to plot by subgroups, transposing the data to put them under one heading is not possible.  Can I simply combine two different bar graphs?

SAS Employee
Posts: 963

Plotting two variables on one graph

Hmm ... well, if you don't want a line, then you definitely don't want to be using Proc GBarline Smiley Happy

You can combine 2 bar charts with Proc GReplay ... but I don't think the results would be what you're wanting.

Could you possibly post up some example data?

And, better yet, maybe "draw" a picture of the graph you're wanting (scan in a hand-drawn graph, or use a drawing package, or something) to show us what you're wanting?

SAS Super FREQ
Posts: 1,044

Plotting two variables on one graph

Which release of SAS are you using?  With SAS 9.2, you can easily combine multiple bar charts in one graph using GTL, with or without the line.

Post a Question
Discussion Stats
  • 6 replies
  • 967 views
  • 0 likes
  • 3 in conversation