Dear all,
I have a vbar chart with sums of each bar that are displayed inside the bar:
proc gchart data=mydata;
vbar year / sumvar = mysum
group = quartal
type = sum
inside = sum /* that's how the sum is shown inside the bar instead of on top */
discrete;
run;
quit;
That's ok. But now I'd like to rotate the sum by 90 degrees and print them in white font color. And: the sums should be valign center inside the bars. How can I do this?
that's how it should look like:
Best wishes
Eva
Hi.
Probably using annotate. I am not aware of the inside statement to allow for angle, but it may.
Below is a poorly written piece of code (just a bad programming day) but it gets what you want done.
Since I didn't have a sample data, I used sashelp.class; the idea is that instead of using "inside = sum" statement in your PROC GHART, you use an annotate data set to place the SUMs where you want them.
/*calculate the sums needed to place on the bars*/
proc summary data = sashelp.class print sum;
var weight;
class sex;
ods output Summary = sum;
run;
/*bring the SUMs over to your original data set - there is a quicker and better way of doing this, but now the brain doesn't work*/
proc sort data = sum;by sex;
proc sort data = sashelp.class out = temp;by sex;
data for_anno;
merge temp sum;
by sex;
run;
/*create the annotate data set*/
data anno;
set for_anno;
retain xsys ysys "2" hsys "3" when "a" ;
function = "label"; color = "black" ;style = '"Times New Roman/bold"' ;
size = 2.7 ;color = "White";angle = 90;
text = put(weight_sum, 6.0);midpoint = sex ;x = weight; y = 345;output;
run;
proc gchart data=sashelp.class anno = anno;
vbar sex / sumvar = weight
type = sum
discrete;
run;quit;
Good luck.
If things work horribly, please provide some sample data.
Anca.
Hi.
Probably using annotate. I am not aware of the inside statement to allow for angle, but it may.
Below is a poorly written piece of code (just a bad programming day) but it gets what you want done.
Since I didn't have a sample data, I used sashelp.class; the idea is that instead of using "inside = sum" statement in your PROC GHART, you use an annotate data set to place the SUMs where you want them.
/*calculate the sums needed to place on the bars*/
proc summary data = sashelp.class print sum;
var weight;
class sex;
ods output Summary = sum;
run;
/*bring the SUMs over to your original data set - there is a quicker and better way of doing this, but now the brain doesn't work*/
proc sort data = sum;by sex;
proc sort data = sashelp.class out = temp;by sex;
data for_anno;
merge temp sum;
by sex;
run;
/*create the annotate data set*/
data anno;
set for_anno;
retain xsys ysys "2" hsys "3" when "a" ;
function = "label"; color = "black" ;style = '"Times New Roman/bold"' ;
size = 2.7 ;color = "White";angle = 90;
text = put(weight_sum, 6.0);midpoint = sex ;x = weight; y = 345;output;
run;
proc gchart data=sashelp.class anno = anno;
vbar sex / sumvar = weight
type = sum
discrete;
run;quit;
Good luck.
If things work horribly, please provide some sample data.
Anca.
Dear Anca,
thanx for your code. The problem is that I don't yet know annotate. Is there maybe a simpler solution within the proc gchart procedure?
Best wishes,
Eva
Hi Eva.
I am not aware of ways to manipulate the "inside" statement (which is what you'd need to do).
If you try the annotate code, you shall see it is not as bad.
And annotate can be quite powerful.
Best of luck.
Anca.
Dear Anca,
I read the annotate book now "Annotate simply the basics" and indeed - annotate is quite easy. Thanx for your code. It works 🙂
Best wishes
Eva
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!
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.
Ready to level-up your skills? Choose your own adventure.