BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
djbateman
Lapis Lazuli | Level 10

I have created a waterfall plot using PROC GPLOT and the NEEDLE interpolation.  I want to display a frequency table on the plot (the table is created in the attached SAS code).  The table should be added to the bottom left corner of the plot and look like this:

PositiveNegative
Increased4022
Stable116
Decreased84

I know I can use an annotate dataset to add the table to the plot, but I have never used anno datasets and have no idea where to start.  I am having no luck trying to teach myself.  Can someone give me some help here?  I also only have SAS 9.1, so I cannot use the SG procedures, which I hear does this quite easily.

1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

This should get you started with the basics (column headers could be added, and annotated move/draw lines or poly/polycont polygons or move/box could be used to draw boxes around the text - it's all a matter of geometry and working out the coordinates):

data table;
category='Increased'; positive=40; negative=22; output;
category='Stable'; positive=11; negative=6; output;
category='Decreased'; positive=8; negative=4; output;
run;

data anno_table; set table;
length text $20;
xsys='1'; ysys='1'; hsys='3'; when='a'; function='label';
y=95-_n_*5;
x=5; position='6'; text=trim(left(category)); output;
x=20; position='4'; text=trim(left(positive)); output;
x=25; position='4'; text=trim(left(negative)); output;
run;

proc gplot data=sashelp.class anno=anno_table;
plot height*weight;
run;

View solution in original post

5 REPLIES 5
art297
Opal | Level 21

A lot of nice examples, including the code, can be found on Robert Allison's page ( http://robslink.com/SAS/Home.htm ).

Take a look, e.g., at group 17.  One at the bottom left side of the page includes a table on the bottom left part of the output.

GraphGuy
Meteorite | Level 14

You can do things like this with annotate (using function='label'), but there's no easy cookie-cutter code that I can provide.  It all depends on the exact specifics of what you want...

Does the table always have 3 rows, or does it need to grow & shrink depending on how many 'bars' are in the waterfall chart?

Do you want the table in the same png file, but beside the graph, or inside the axes of the graph?  If inside the axes, is there guaranteed to always be white-space there?  (Beside the graph, you can guarantee white-space by using an angled blank title on the left or right of the graph).

Does the table have to have boxes drawn around it, or could it be just the words? (just the words is much simpler).

Here are some other examples with an annotated table, but none are exactly what you're wanting (just sort of randomly choosing a few - but none are really good simple/learning ones):

http://robslink.com/SAS/democd21/elecgage_info.htm

http://robslink.com/SAS/democd19/sfew_info.htm

http://robslink.com/SAS/democd33/subprime_info.htm

http://robslink.com/SAS/democd44/ex_29_info.htm

Unless you *reall/really* need to have the table sharing the same space as the graph, I would recommend putting the table under the graph (but on the same webpage) - then you can use a simple "proc print" (or other html table-creating procs).  These can really/truly be put together on the same webpage to look quite nice:

http://robslink.com/SAS/democd29/robslink_info.htm

djbateman
Lapis Lazuli | Level 10

Robert,

Thank  you for your response.

For these plots, all tables will have 3 rows.

I would prefer the table to be inside the axes, but if it is too much of a hassle, I may need to be more flexible.

I would also prefer the box around the data, but again, I can be flexible here.

I will keep looking at SAS papers and play around with the different annotate variables.  I found a paper by Art Carpenter that may help out a lot.

Thanks again!

GraphGuy
Meteorite | Level 14

This should get you started with the basics (column headers could be added, and annotated move/draw lines or poly/polycont polygons or move/box could be used to draw boxes around the text - it's all a matter of geometry and working out the coordinates):

data table;
category='Increased'; positive=40; negative=22; output;
category='Stable'; positive=11; negative=6; output;
category='Decreased'; positive=8; negative=4; output;
run;

data anno_table; set table;
length text $20;
xsys='1'; ysys='1'; hsys='3'; when='a'; function='label';
y=95-_n_*5;
x=5; position='6'; text=trim(left(category)); output;
x=20; position='4'; text=trim(left(positive)); output;
x=25; position='4'; text=trim(left(negative)); output;
run;

proc gplot data=sashelp.class anno=anno_table;
plot height*weight;
run;

Cynthia_sas
SAS Super FREQ

In addition to Robert's excellent example, using GPLOT and ANNOTATE, the SGPLOT procedure with the NEEDLE statement can come close. If you are using 9.2, you'd have to stick with the INSET statement. If you are in 9.3, then the SG procedures do have annotation capability. Using your WATERFALL dataset, you should be able to see what this looks like using SAS 9.2 or higher.

cynthia

ods listing style=listing;
proc sgplot data=waterfall cycleattrs;
  title 'Best Percent Change in Tumor Size';
  where brpercent^=.;
  needle x=n y=brpercent / name='n1'
         group=posneg lineattrs=(thickness=3 pattern=1);
  yaxis grid label='Percent Change in Tumor Size';
  xaxis type=linear values=(1 to 91 by 1)  display=none;
  keylegend 'n1' / across=1 position=topright location=inside noborder;
  inset "                    Pos Neg"
        "Increased  111 112"
        "Stable         221 222"
        "Decreased 331 332" / position=bottomleft valuealign=left
                              border title="Inset Table 1";
  inset ("Increased"="111" "Stable"="222" "Decreased"="333")/
          position=bottom valuealign=left
          border title='Inset Table 2';

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 2350 views
  • 6 likes
  • 4 in conversation