Data visualization with SAS programming

vbar: sum inside bar, rotated and diffent color

Accepted Solution Solved
Reply
Regular Contributor
Regular Contributor
Posts: 156
Accepted Solution

vbar: sum inside bar, rotated and diffent color

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:

vbar_sum_inside.gif

Best wishes

Eva


Accepted Solutions
Solution
‎12-13-2012 08:46 AM
Super Contributor
Posts: 543

Re: vbar: sum inside bar, rotated and diffent color

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.

View solution in original post


All Replies
Solution
‎12-13-2012 08:46 AM
Super Contributor
Posts: 543

Re: vbar: sum inside bar, rotated and diffent color

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.

Regular Contributor
Regular Contributor
Posts: 156

Re: vbar: sum inside bar, rotated and diffent color

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

Super Contributor
Posts: 543

Re: vbar: sum inside bar, rotated and diffent color

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.

Regular Contributor
Regular Contributor
Posts: 156

Re: vbar: sum inside bar, rotated and diffent color

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 417 views
  • 0 likes
  • 2 in conversation