Date: Mon, 17 Jul 2006 15:13:41 -0400
Reply-To: "Gerstle, John (CDC/NCHSTP/DHAP) (CTR)" <yzg9@CDC.GOV>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Gerstle, John (CDC/NCHSTP/DHAP) (CTR)" <yzg9@CDC.GOV>
Subject: Re: Making really nice just about ready to go tables
Content-Type: text/plain; charset="US-ASCII"
This is a quick answer to your question. It can be done easily, with
some work on the frontend. Once you have a template, you can re-use it
with minimal modifications (using macro code as needed, especially with
I'm going to skip the data step code and show some ODS and PROC
First, I'd run a handful of PROC FREQS, output the resulting tables
using ODS OUTPUT, then piece this dataset together.
ods output onewayfreq=demog;
proc freq data=foo; table (gender age education)*group / missing; run;
ods output close;
...if group is your Control and Experimental groups. (You'll need to
transpose the frequency or percents values by group to get the dataset
Next, build the dataset you want to report out - something like so
(suggested variable names in the first row - look at the ODS dataset via
PROC PRINT to fix this the way you want it...):
Varname Varvalue control_pct control_num_denom exp_pct
Gender Male 52.6 (312/593)
Gender Female 47.4 (281/593) 45.6
Age < 15 years 8.2 (48/588) 7.5
Age 15 - 45 years 79.3 (466/588) 76.7
Age > 45 years 12.6 (74/588) 15.8
Assign the formatted value to Varvalue, or define a rather complicated
format to cover all your demographic values.
I'd create a character variable, control_num_denom, that concatenates
the parentheses, numerator and denominator values for each demographic
Then the untested, simple (skips a lot of the bells and whistles) PROC
REPORT code, with ODS...
Ods html file="<path>\Table 1.xls" stle=journal;
Title "Table 1. Demographic characteristics (n = 1205).";
Proc report data=builtabove nowdw ;
Columns (" " Varname Varvalue)
("Control/(n = 594)" control_pct control_num_denom)
("Experimental Group/(n = 611)" exp_pct
Define varname / " " group ;
Define varvalue / " " ;
Define control_pct / "%" format=8.1;
Define control_num_denom / "(frequency/total)";
Define exp_pct / "%" format=8.1;
Define exp_num_denom / "(frequency/total)";
Break after varname / skip;
Ods html close;
Look up the vast plethora of PROC REPORT, TABULATE, with ODS papers at
John Gerstle, MS
CDC Information Technological Support Contract (CITS)
NCHSTP \DHAP \HICSB \Research, Analysis, and Evaluation Section
Centers for Disease Control and Prevention
"As far as the laws of mathematics refer to reality, they are not
certain; and as far as they are certain, they do not refer to reality."
Albert Einstein, addressing the Prussian Acadamy of
Science, Berlin , Jan 27, 1921
"Boss. We've got cats." "Meow"
From: firstname.lastname@example.org [mailto:email@example.com]
On Behalf Of Jennifer Sabatier
Sent: Monday, July 17, 2006 2:36 PM
Cc: Jennifer Sabatier
Subject: Making really nice just about ready to go tables
I know that this is just about impossible, getting tables out of SAS
look just about ready for submission to a journal. But, perhaps I can
I'm familiar, though not expert with using PROC REPORT and PROC
know some of this can be done using a data step and put statements and
that's where I am really inexperienced.
Here's what I want my table to look like (a sample from a table I made
doing a lot of goofing around in EXCEL and WORD, taking 4 times the
of time I'm sure it should). I hope it posts right!
Table 1. Demographic characteristics (n = 1205).
Control Experimental Group
(n = 594) (n = 611)
Gender % (frequency/total) %
Male 52.6% (312/593) 54.4% (331/608)
Female 47.4% (281/593) 45.6% (277/608)
< 15 years 8.2% (48/588) 7.5% (45/600)
15 - 45 years 79.3% (466/588) 76.7% (460/600)
> 45 years 12.6% (74/588) 15.8% (95/600)
None 57.1% (335/587) 53.4% (316/592)
Grades 1 - 3 4.6% (27/587) 7.9% (47/592)
Grades 4 and 5 4.3% (25/587) 4.7% (28/592)
Grade 6 34.1% (200/587) 34.0% (201/592)
The variables are coded, ie, Gender = 1 or 2, Age = 1, 2, or 3, etc.
Missing variables are coded as . and are excluded from the calculation
percent (as you can see, the percentages come from the denominator of
data was available). I specifically want to include the correct
denominator, because that's how I am representing the missingness. The
total n for each group is listed in the column label.
What can I use, data stepping, any proc, whatever, to get a table in
format, with percentage signs, the parentheticals, then slash for the
If anyone has any code that comes close and I can modify it would save
HOURS of time that I could spend on actual analysis of other projects,
instead of goofing around with tables.
And if you think I'm just a whiner who needs to realize that spending
making tables for publication is just how it has to be, feel free to
that to. At least then I can move on to the next shortcut hunt...