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

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

1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

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

11 REPLIES 11
GraphGuy
Meteorite | Level 14

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;

JasonL
Quartz | Level 8

Thank you very much Robert!  It worked. Jason

JasonL
Quartz | Level 8

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


GraphGuy
Meteorite | Level 14

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

JasonL
Quartz | Level 8

Thanks Robert.  Will have a try. Jason

JasonL
Quartz | Level 8

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

GraphGuy
Meteorite | Level 14

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

JasonL
Quartz | Level 8

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

GraphGuy
Meteorite | Level 14

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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