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

I've been trying to figure out how to have a bar chart (representing exposure) on the second y axis and a line chart (representing frequency) on the first y axis in sgplot.  Can anybody help?

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

In SAS 9.4 we have added the ability to assign bar charts to secondary axes. In SAS 9.2 and 9.3, you should be able to assign the bar chart (vbar) to the first Y axis and the line chart (vline) to the secondary Y axis. Here is a simple example.

proc sgplot data=sashelp.class;

vbar age / response=height stat=mean;

vline age / y2axis;

run;

Hope this helps!

Dan

View solution in original post

4 REPLIES 4
AncaTilea
Pyrite | Level 9

Sure thing.

proc gbarline works wonders for this sort of graphs.

Also, has a magnificent website where you can find plots (with WORKING SAS code)

http://robslink.com/SAS/democd7/aaaindex.htm

Good luck!

Anca.

dal233
Calcite | Level 5

I've just resolved this.  I was using a series statement instead of a vline statement for the line graph.  If I use vline it works with the y2axis option.

proc sgplot data = test;

vline year / response = frequency y2axis;

vbar year / response = gwp;

run;

Strangely though, the vbar statement does not offer the y2axis option.

DanH_sas
SAS Super FREQ

In SAS 9.4 we have added the ability to assign bar charts to secondary axes. In SAS 9.2 and 9.3, you should be able to assign the bar chart (vbar) to the first Y axis and the line chart (vline) to the secondary Y axis. Here is a simple example.

proc sgplot data=sashelp.class;

vbar age / response=height stat=mean;

vline age / y2axis;

run;

Hope this helps!

Dan

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
  • 4 replies
  • 7519 views
  • 3 likes
  • 4 in conversation