BookmarkSubscribeRSS Feed
djbateman
Lapis Lazuli | Level 10

Is there a simple way to add a frequency table to a SAS graph without creating an annotate dataset?  (I have not had time to figure out annotations yet, althought I know they can come in quite handy.)  I am making a "waterfall" chart using the INTERPOL=NEEDLE option in the SYMBOL statement.  I want to overlay on the plot a frequency table that shows the counts of patients that are above, below, or between a given range.

I have seen plots where the data table is below the graph (I think it was summary data below a bunch of side-by-sde boxplots), but I don't want that.  I want an actual table on the graph itself.

4 REPLIES 4
GraphGuy
Meteorite | Level 14

I don't think there's any way to do this automatically - you'll have to use one of the 'tricks' to add extra text.

I would probably use annotate, and programmatically position the text using a data step.

There are several other tricks you can use to get text on a graph, such as using 'note' statements, or writing the text on a gslide, and then 'greplay' that gslide onto the chart.  But nothing easy/automated that I know of.

Rick_SAS
SAS Super FREQ

Use PROC SGPLOT and use the statement

scatter x=x y=y / MARKERCHAR=cell x2axis

where x and y are the coordinates in the table and cell is contents of the cell. See p. 11 of Sanjay's paper http://www.pharmasug.org/proceedings/2011/SAS/PharmaSUG-2011-SAS-AD01.pdf

MikeZdeb
Rhodochrosite | Level 12

Hi ... one idea without annotation is to use a legend to put extra information on SAS/GRAPH output .  I used SQL to create a macro variable with

text for the legend (it might have been just as easy to type out the entries !!!).  Anyways, the following inserts something that looks

a bit like a table in the upper left portion of the plot.  Every J=L produces a new line in the legend.

proc sql noprint;

create view counts as

select distinct put(date,monname. -l) as month, put(sum(air),comma.) as freq

from sashelp.air

group month

order month(date);

select cat('j=l "',strip(month),' : ',strip(freq), '"') into :tmp separated by ' '

from counts;

quit;

goptions reset=all ftext='calibri' htext=2 gunit=pct

device=png xpixels=1024 ypixels=768 gsfname=gout;

legend1

position=(top inside left)

label=(position=top j=l "TRAVEL BY MONTH (1000s)" j=l ' ' &tmp)

shape=symbol(.00001,.0001) value=none;

symbol f='wingdings' v='6c'x c=blue h=2 i=smp66 l=2 w=2;

axis1 label=(a=90 'TRAVEL (1000s)');

axis2 label=('MONTH AND YEAR') offset=(2,2)pct;

title1 ls=2;

filename gout 'z:\plot_table.png';

proc gplot data=sashelp.air;

plot air*date/ legend=legend1 vaxis=axis1 haxis=axis2 noframe;

format date monyy.;

run;

quit;



plot_table.png
Jay54
Meteorite | Level 14

If you are using SAS 9.2, you can use SG Procedures or GTL to add statistics tables to your graphs without resorting to annotation.  Rick pointed to a way using SG Procedures.  For more flexibility, you can use GTL.  Please see my recent blog post on this subject.  Axis aligned statistics tables can be added along the horizontal or vertical, discrete or interval axis.

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