I'm trying to replicate a PDF (from Excel) report in SAS 9.2 and I haven't found the best solution although there seem to be many possible approaches.
The single page PDF report contains 3 small tables and a table with data and horizontal bars with percentages. The tables / reports are no problem but I haven't figured out how to create a table with horizontal bars that looks good. I found an example in a link posed by Sanjay in the beginning of this forum which has almost what I'm trying to get - a table of statistics with hbars with golf data.
The structure of the example has columns with age, events, wins, player's name, and earnings in a hbar chart. My data are similar but the player's name column needs to be the left most column and left justified. It seems that there are no options to change it from right justified. This looks like the conclusion in the thread "SGPLOT: Wrap & Left Justify Tickmark Values" from Oct 8th.
One workaround is to use a monospace font and make the names the same length. This aligns the data to the left, but it doesn't look very good.
I also thought of an alternative based on traffic lighting examples. If it's possible to control the formatting of a cell, I shoulld be able to create a table template if I can find a character format to simulate bars.
Can anyone think of a better way or is the only alternative to send the data to Excel and format it there?
The example you point to uses the new "proc template" and "proc sgrender".
I'm not an expert at that, so I'm not sure if you can control the justification there.
But I have re-written the example, using traditional "old school" SAS/Graph
proc gchart, with the table programmatically annotated to the side, and
you can easily control the justification of the player names (ie, bar labels)
using the axis statement:
data my_anno; set PGA2007;
length text $50 style $20;
function='label'; style='"arial"'; hsys='3'; when='a';
/* annotate totals at end of bars */
/* annotate the values for the table to the left of the bar chart */
x=5; text=trim(left(Age)); output;
x=12; text=trim(left(Events)); output;
x=19; text=trim(left(Wins)); output;
length text $50 style $20;
function='label'; style='"arial/bold"'; hsys='3'; when='a';
/* annotate the headings for the table to the left of the bar chart */
x=5; text="Age"; output;
x=12; text="Events"; output;
x=19; text="Wins"; output;
/* combine all your anno stuff */
data my_anno; set my_anno headings;
title1 "Professional Golf Statistics for 2007";
/* fake/blank title, to add white space on the left (don't try it with dev=java or activex!) */
title2 angle=90 height=30pct " ";
pattern1 v=s c=cx9BC4E2;
proc gchart data=PGA2007 anno=my_anno;
hbar Player / type=sum sumvar=Earnings descending nostats
autoref cref=graydd clipref
added 'pre' tags around code, as recommended by Peter C.
very impressive implementation.
but beware, ....
when test running code copied from the message, "age" is pulled into the player name. The conflict was between forum message handling (equivalent of left(compbl(code)) ) and the format modifier & [accepting a single blank within a string, requires double blank to terminate string]. In fact more than age might be pulled into name, as the 15 characters starting at the beginning of the name will be swallowed as "Player" recommendation (1) post unalterable code within [pre [/pre tags or (2) ensure strings that require the "&" input modifier appear last, or (3) lobby for a [code tag that more easily pastes into SAS (not needing to be pasted into wordpad first)
Message was edited by: Peter.C
I just wanted to follow up on this. I saw the notes on using annotate - forgot about this approach entirely. My opinion is that you can do almost anything with it but it's more complex and requires different skills and more training.
The GTL workarounds seem to get close to my goal of left justifying a label.
define Style BarTableHorzStyle;
parent = styles.journal;
style GraphFonts from GraphFonts / 'GraphDataFont' = (", ",10pt);
style graphaxislines from graphaxislines / contrastcolor=white;
/* keep axis but hide it. it needs to exist to or the labels are centered */
ods pdf file="c:\temp\BarTableHorz4.pdf" style=BarTableHorzStyle;
proc sgrender data=PGA2007 template=BarTableHorz;
ods pdf close;