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

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

1 ACCEPTED SOLUTION

Accepted Solutions
AncaTilea
Pyrite | Level 9

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

4 REPLIES 4
AncaTilea
Pyrite | Level 9

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.

Eva
Quartz | Level 8 Eva
Quartz | Level 8

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

AncaTilea
Pyrite | Level 9

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.

Eva
Quartz | Level 8 Eva
Quartz | Level 8

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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