As a programmer, I arrived very late onto the scene of using ODS. My initial use for it, as a clinical programmer, was picking up the statistical values coming out of stats procedures. Only in 2007 did I turn my attentions into using ODS to improve the layout of what were previously purely text tables. I expected to have to learn a lot, to get out what I wanted but was pleasantly surprised to discover that I did not need to learn anything at all. ODS does all the work for you.
I am assuming that your tables are coming out of "proc report" or perhaps "proc tabulate" (that I haven't used in years) because it is only sas procedures that have ODS support. If you produce reports using "data _null_" then ODS facilities exist but it is no easy matter.
All you have to do is declare an RTF ("Rich Text Format") file name
and optionally a template style before you call a sas procedures and then
close the RTF stream after the procedure ends. Like this:
| ods rtf file="file-destination" style=name-of-style;
proc report ...... ;
ods rtf close; |
What you end up with is your normal plain-text output but with an extra output in "Rich Text Format" (RTF) in the file name you specified that can be incorporated into a word processor document. There you will be able to manipulate the table, edit it, color it, change its text, its font, its size etc..
Many other output formats are available. For example, "ods html" will give you html output.
As I mentioned previously, I am very late onto the scene of ODS for table output and I assumed it would have only limited capabilities. I was wrong. I am going to show you an example that I thought ODS would not be able to cope with but it coped with it perfectly.
| footnote1 j=l "^ Fisher's exact test" "%sysfunc(repeat(%str(
),200))" ;
footnote2 j=l "# Student's t test" "%sysfunc(repeat(%str( ),200))" ; %unistats(dsin=demog,unicatrep=yes,total=yes,
|
What you see above is a call to my %unistats macro. It will produce a plain text table, an RTF table and an HTML table. You can see near the end of the call to the macro the two parameters odsrtf= and odshtml= and this gets used inside the macro just before the "proc report" step. It has to be done this way, rather than set up the "ods rtf" and "ods html" statements before the macro call, as the macro calls stats procedures that would be affected by the "ods" statements and I do not want to capture their output. I just want the table so that is why these statements must be enacted inside the macro just before the "proc report" step. Notice that the odsrtf= parameter value contains the word "bodytitle" at the end (works with SAS v9.1.3). This is to force titles and footnotes to be shown with the table rather than in document header and trailer lines. The odshtml= call does not need this. Now, if you look at the start of the code, I will explain the footnote statements. I have the option "center" in effect so I left-align the footnotes for the plain text report by padding out with spaces. This is what the %sysfunc() call is doing. However, this technique of padding out with spaces will get ignored in the RTF and HTML output so I have to use the "j=l" (justification equals left) statement. For the plain text report, the "j=l" will be ignored but it will be used for the RTF and HTML output. If I didn't want the plain text output then I could suppress it with the statement "ods listing close;" before the call to the macro and reinstate listing output using "ods listing;" afterwards but the plain text output is useful for a comparison with the rtf table and html table.
When I run the code, these are the outputs I get:
Plain text table
|
Number of Patients (%) /
Descriptive Statistics
Ambicor Betamaxin
Gender
Race
Age (yrs)
N
9
8
17
Weight (kg)
^ Fisher's exact test
|
html table
The html output looks good but note that the column headers for "Total" and "p-value" do not go down to the bottom line as they should do. You can link to the html table here.
rtf table
What you will see is the default layout for the rtf table. You can specify
a style if you want to to improve the look but you can edit the table to
change colors and fonts from within a word processor. The rtf table is
best viewed using a word processor such as MS Word so that you can see
how easy it is to edit the table and improve its layout. You can link to
the rtf table here.
Go back to the home page.
E-mail the macro and web site author.