BookmarkSubscribeRSS Feed
VD
Calcite | Level 5 VD
Calcite | Level 5
I'm facing two issues in plotting histograms in gchart, if anyone could advise please?

1) How to display y-axis on both the sides of the graph, one side displaying frequencies and the other side displaying percentages?

2)On the x-axis, how to label the bars only after (say) 5 points and yet display all the bars? For instance, how to have a bar for each point from 0 to 80 (0,1,2..80) and display the labels for bars only at (0, 5, 10...80)?

I tried in proc univariate as well but couldn't work it out. Thanks.
Vikas
3 REPLIES 3
GraphGuy
Meteorite | Level 14
The easiest way to get an axis on the left & right side of a bar chart is using "proc gbarline". If your version of SAS is not new enough to have gbarline, then you could use "proc gchart" and then annotate the tickmarks & values along the right-side of the graph (a little tricky, but do-able).

Here's some basic gbarline code, to get you started:

data foo;
input barnum value pct;
format pct percent5.0;
datalines;
1 2 .20
2 5 .50
3 3 .30
;
run;

symbol1 value=none interpol=none;
proc gbarline data=foo;
bar barnum / type=sum sumvar=value;
plot / sumvar=pct;
run;
VD
Calcite | Level 5 VD
Calcite | Level 5
Robert, this is very helpful. Thanks for both the answers. Vikas.
GraphGuy
Meteorite | Level 14
Per your 2nd question - you can use an axis statement with "proc gchart", and it will let you specify custom text (including a blank value) for each tickmark value of the axis, referring to them by number ( t=1 is the first bar midpoint value, t=2 is the second, and so on).

Here is some sample code, that shows how to blank out the first 5 values:

axis1 value=(t=1 '' t=2 '' t=3 '' t=4 '' t=5 '');

proc gchart data=sashelp.class;
hbar name / type=sum sumvar=height maxis=axis1;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 3 replies
  • 1606 views
  • 0 likes
  • 2 in conversation