Data visualization with SAS programming

Using gbarline, is there a way to plot 2 lines on same graph?

Reply
N/A
Posts: 0

Using gbarline, is there a way to plot 2 lines on same graph?

I'd like to show the change in use of something over time (left y axis (bar)=% use; x-axis= year) by the growth in # of something else (right y-axis (line)). But, there are two subgroups for the line plot. Is there any way to get this on 1 graph rather than have a separate graph for each subgroup of axis 3?

Thanks!
SAS Super FREQ
Posts: 864

Re: Using gbarline, is there a way to plot 2 lines on same graph?

What version of SAS are you using?
N/A
Posts: 0

Re: Using gbarline, is there a way to plot 2 lines on same graph?

Windows 9.1.3 SP 4
SAS Super FREQ
Posts: 864

Re: Using gbarline, is there a way to plot 2 lines on same graph?

Hey Julie,

In SAS 9.2, this is very simple to do. In 9.1.3, I had to take a more creative approach. Try the sample below and see if you can make it work for you.

Thanks!
Dan

/* summarize your data */
proc means data=sashelp.class noprint;
class age sex;
var weight height;
output out=class mean=;
run;

/* Adjust some fields for correct plotting */
data class2;
set class;
if (_type_ ne 2) then weight=.;
if (_type_ ne 3) then height=.;
if (sex eq " ") then sex="M";
run;

symbol1 i=needle width=40 color=blue;
symbol2 i=join;
axis1 offset=(5pct, 5pct) minor=none;
axis2 order=(0 to 150 by 25) offset=(0,0);
axis3 order=(0 to 80 by 20) offset=(0,0);

proc gplot data=class2;
plot weight*age / haxis=axis1 vaxis=axis2;
plot2 height*age=sex / vaxis=axis3;
run;
N/A
Posts: 0

Re: Using gbarline, is there a way to plot 2 lines on same graph?

Thanks -- I will give it a shot!
N/A
Posts: 0

Re: Using gbarline, is there a way to plot 2 lines on same graph?

btw, can you tell me the code for version 9.2? I may have access to it...thx
SAS Super FREQ
Posts: 864

Re: Using gbarline, is there a way to plot 2 lines on same graph?

In 9.2, gbarline supports multiple plot lines. Therefore, you can pull your subgroup into separate columns and use gbarline. Here's a simple example:

data class;
set sashelp.class;
if (sex="F") then female=height;
if (sex="M") then male=height;
run;

proc gbarline data=class;
bar age / sumvar=weight;
plot / sumvar=female;
plot / sumvar=male;
run;
Post a Question
Discussion Stats
  • 6 replies
  • 132 views
  • 0 likes
  • 2 in conversation