Data visualization with SAS programming

Adding Numbers below vertical bars using the Annotate Facility

Accepted Solution Solved
Reply
Contributor
Posts: 37
Accepted Solution

Adding Numbers below vertical bars using the Annotate Facility

I was trying to add a data table at the bottom of the chart below the bars (Just numbers for now, no table lines yet).  The attached is my code.  Obviously something is not right.  Can somebody have a look and help me out?

Thanks a lot!

Jason

Attachment

Accepted Solutions
Solution
‎05-30-2012 09:19 AM
SAS Employee
Posts: 967

Re: Adding Numbers below vertical bars using the Annotate Facility

I think something like this should do it...

PROC FORMAT;
      VALUE Cat      1 = "IP_Modelled"
                        2 = "DS_Modelled"
                        3 = "IP_Non_Modelled";
      VALUE LHIN  1 = "ESC"
                        2 = "SW"
                        3 = "WW"
                        4 = "HNHB"
                        99 = "Prov";
RUN;

data LHINs;
      input LHIN_no Category Pct_Weighted_Cases;
cards;
1      1      0.600896443
1      2      0.146378784
1      3      0.243097067
2      1      0.603088692
2      2      0.116757141
2      3      0.263761607
3      1      0.610733985
3      2      0.153525711
3      3      0.223676414
4      1      0.583121449
4      2      0.115212779
4      3      0.291048408
99      1      0.56620322
99      2      0.118356681
99      3      0.291827851
;
run;

data MyAnno;
      set LHINs;
      length function color $8. text $20. style $20.;
      retain xsys '2' ysys '3' position 'E' style 'arial' color 'black' when 'a';
      function='label';
      midpoint=LHIN_no;                                                                                                                                
      text=trim(left(put(Pct_Weighted_Cases,Percent10.1)));
      if Category=1 then y=15;
      if Category=2 then y=10;
      if Category=3 then y=5;
run;

goptions RESET=all border hsize=10.5in vsize=8in htext=12pt;

pattern1 value=solid color=blue;
pattern2 value=solid color=yellow;
pattern3 value=solid color=maroon;
                                                                                                                                                                                                                                                                                                               
Title1 height=16pt ls=1.5 "Percent Weighted Cases Modelled and Non-Modelled, by LHIN, 2010/11";
Title2 height=4pt " ";
Footnote1 height=15pct " ";  /* make space for annotated table */

axis1 label=none order=(0 to 1 by .2) minor=none offset=(0,0);

axis2 label=none;

Proc gchart data=LHINs;
      format Pct_Weighted_Cases percent6.;
      format Category Cat.;
      format LHIN_no LHIN.;
      vbar LHIN_no / discrete
      sumvar=Pct_Weighted_Cases
      subgroup=Category                                                                                                                                
      autoref cref=grey clipref nolegend
      raxis=axis1 maxis=axis2
      anno=MyAnno;
run; quit;

View solution in original post


All Replies
Solution
‎05-30-2012 09:19 AM
SAS Employee
Posts: 967

Re: Adding Numbers below vertical bars using the Annotate Facility

I think something like this should do it...

PROC FORMAT;
      VALUE Cat      1 = "IP_Modelled"
                        2 = "DS_Modelled"
                        3 = "IP_Non_Modelled";
      VALUE LHIN  1 = "ESC"
                        2 = "SW"
                        3 = "WW"
                        4 = "HNHB"
                        99 = "Prov";
RUN;

data LHINs;
      input LHIN_no Category Pct_Weighted_Cases;
cards;
1      1      0.600896443
1      2      0.146378784
1      3      0.243097067
2      1      0.603088692
2      2      0.116757141
2      3      0.263761607
3      1      0.610733985
3      2      0.153525711
3      3      0.223676414
4      1      0.583121449
4      2      0.115212779
4      3      0.291048408
99      1      0.56620322
99      2      0.118356681
99      3      0.291827851
;
run;

data MyAnno;
      set LHINs;
      length function color $8. text $20. style $20.;
      retain xsys '2' ysys '3' position 'E' style 'arial' color 'black' when 'a';
      function='label';
      midpoint=LHIN_no;                                                                                                                                
      text=trim(left(put(Pct_Weighted_Cases,Percent10.1)));
      if Category=1 then y=15;
      if Category=2 then y=10;
      if Category=3 then y=5;
run;

goptions RESET=all border hsize=10.5in vsize=8in htext=12pt;

pattern1 value=solid color=blue;
pattern2 value=solid color=yellow;
pattern3 value=solid color=maroon;
                                                                                                                                                                                                                                                                                                               
Title1 height=16pt ls=1.5 "Percent Weighted Cases Modelled and Non-Modelled, by LHIN, 2010/11";
Title2 height=4pt " ";
Footnote1 height=15pct " ";  /* make space for annotated table */

axis1 label=none order=(0 to 1 by .2) minor=none offset=(0,0);

axis2 label=none;

Proc gchart data=LHINs;
      format Pct_Weighted_Cases percent6.;
      format Category Cat.;
      format LHIN_no LHIN.;
      vbar LHIN_no / discrete
      sumvar=Pct_Weighted_Cases
      subgroup=Category                                                                                                                                
      autoref cref=grey clipref nolegend
      raxis=axis1 maxis=axis2
      anno=MyAnno;
run; quit;

Contributor
Posts: 37

Re: Adding Numbers below vertical bars using the Annotate Facility

Thank you very much Robert!  It worked. Jason

Contributor
Posts: 37

Re: Adding Numbers below vertical bars using the Annotate Facility

Hi Robert,

You used a footnote statement to make space for the annotated table.

How do you make space on the left side of the annotated table for some row headings (moving the bar chart to the right)?

Thanks.

Jason


SAS Employee
Posts: 967

Re: Adding Numbers below vertical bars using the Annotate Facility

You can 'angle' a blank title (or footnote) 90 or -90 degrees, to add blank white-space on the left and right of the graph, as follows:

title3 h=7 a=90 " ";

title4 h=15 a=-90 " ";

This is technique described in detail, in Example 7 in my book "SAS/Graph: Beyond the Basics".  Here is the example & code:

http://robslink.com/SAS/book/example07.htm

http://robslink.com/SAS/book/example07_info.htm

Contributor
Posts: 37

Re: Adding Numbers below vertical bars using the Annotate Facility

Thanks Robert.  Will have a try. Jason

Contributor
Posts: 37

Re: Adding Numbers below vertical bars using the Annotate Facility

Thank you again Robert!  This "Angling" technique worked.

I was just looking at the example on "http://support.sas.com/kb/35/774.html".  I don't understand why, in the "Populate the table" segment in the data step creating the Anno data set, there need to be the "move" and "cntl2txt" records.  Shouldn't the "label" records have done the job since they all have the x and y for the locations of the texts?

Thanks.
Jason

SAS Employee
Posts: 967

Re: Adding Numbers below vertical bars using the Annotate Facility

I'm not too familiar with that particular example, but sometimes with certain annotate functions (such as cntl2txt and relative coordinate systems), I find that I sometimes have to use a few 'extra' commands from what would intuitively suffice.

But, if you experiment with the example, and find some places where you can streamline the code and make it easier to understand, be sure to send your new/improved version to tech support - they might update their example with your improvements Smiley Happy

Contributor
Posts: 37

Re: Adding Numbers below vertical bars using the Annotate Facility

Thanks.

Contributor
Posts: 37

Re: Adding Numbers below vertical bars using the Annotate Facility

Hi Robert,

Even though I used the same font for the table row headers as for the table contents (in the attached), the headers appear much thicker.  Why and is there a way to change that?

Thanks.
Jason

Attachment
SAS Employee
Posts: 967

Re: Adding Numbers below vertical bars using the Annotate Facility

Ahh - this is a good question!

View your  MyAnno data set, and you'll notice that there are several observations (rows) for each of the annotated header text (the header being the label to the left).  Each time this same text is printed in the same location, a side-effect of the anti-aliasing algorithm (that creates the smooth-edges on text) is that it can make the text look thicker (or sometimes 'fuzzier') around the edges.

It's a little more work, but you'll want to only have 1 obsn in your annotate data set for each piece of annotated text.  There are several ways to do this: 1) you could use a 'by' variable for each row, and then only output the header for the "first." of the row, 2) you could create the headers first, and then the table text, and then combine the 2 data sets, 3) other ways Smiley Happy

Contributor
Posts: 37

Re: Adding Numbers below vertical bars using the Annotate Facility

Thanks a lot!

☑ This topic is SOLVED.

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

Discussion stats
  • 11 replies
  • 561 views
  • 0 likes
  • 2 in conversation