Good morning,
I have been using SAS 9.4 for some simple analysis, but I use STATA to produce descriptive statistics tables ready to insert in a MS Word document (for instance). In STATA esttab creates rtf (text document). In SAS, I have spent the morning searching online for a “simple” similar way, but I got overwhelmed by the large amount of information and the relatively complex and specific code. This is the reason I am contacting you for help.
Is there a simple way in SAS to produce a table with summary statistics means/nedians/max/sdvt.... ? Perhaps, if I have a template I can modify it.
An example:
data k;
input X $ d y z;
informat d mmddyy8. ;
cards ;
a 01/01/96 5.1 110.500
a 10/27/96 2.3 109.500
a 12/16/96 8.1 110.200
a 01/05/97 9.6 99.000
a 01/11/97 1.6 .
b 02/03/97 6.2 100.269
b 03/25/97 5.8 50.560
b 11/15/98 2.6 42.250
b 01/14/99 4.9 12.160
b 01/29/99 3.7 .
b 03/10/99 4.6 800.000
b 03/10/99 2.3 200.100
c 03/16/99 9.6 5.690
;run;
proc sort data= k; by x; run;
proc univariate data=k noprint ;
var y z;
by x;
output out= tabl
mean = mean_y mean_z
median = median_y median_z
n= n_y n_z
max =max_y max_z
min= min_y min_z
std = st_y st_z;
;run;
proc print data = tabl; run;
The question is: is there a way of using this information to produce a table similar to this:
|
For individual a |
|||
Vble |
Obs |
Mean (median) |
Max (min) |
std |
Y |
5 |
5.340 (5.100) |
9.600 (1.600) |
3.502 |
Z |
4 |
107.300 (109.850) |
110.500 (99.000) |
5.549 |
|
For individual b |
|||
|
Obs |
Mean (median) |
Max (min) |
std |
Y |
5 |
3.860 (3.700) |
76.268 (46.405) |
1.491 |
Z |
4 |
107.300 (5.100) |
110.500 (99.000) |
84.187 |
|
For ind c |
|||
|
Obs |
Mean (median) |
Max (min) |
std |
Y |
1 |
9.600 (9.600) |
9.600 (9.600) |
|
Z |
1 |
5.690 (5.690) |
5.690 (5.690) |
|
Thank you for your help,
Tomas
If it has to look like
110.500
(99.000)
in a single cell, those are not easily produced from SAS, and there have been several discussions about this in this forum.
However, if you want the maximum in one cell and the minimum in the cell next to it, those are easily produced via PROC REPORT, and yes, you can export to RTF.
ods rtf file="g:\foldername\example.rtf";
proc report data=k;
columns x y y=median_y y=min_y y=max_y z z=z_median;
define x/group;
define y/mean "Y Mean";
define median_y/median "Y Median";
define min_y/min "Y Min";
define max_y/max "Y Max";
define z/mean "Z Mean";
define z_median/median "Z Median";
run;
ods rtf close;
Thank you Paige.
I need time to do this in SAS. For now I will continue using STATA.
But thank you for your time,
Tomas
Even though that macro works as stated, I still feel that @Thomas_mp would be better off learning PROC REPORT, and by not forcing the output to appear in the old-fashioned appearance exactly as in his original post.
@Reeza wrote:
Except that's still the standard for journal publications and reports...
Not stated by the OP as a requirement.
And just for giggles using one data set and showing some different tables possible with Proc Tabulate:
proc tabulate data=k; class x; var y z; table x='For individual: ' , y z, n='Obs' mean median max min std /misstext=' ' ; table x='Individual' *(y z), n='Obs' mean median max min std /misstext=' ' ; table y z, x='For individual: '*( n='Obs' mean median max min std) /misstext=' ' ; table (y z)*( n='Obs' mean median max min std), x='For individual: ' /misstext=' ' ; run;
Please post code in a code box opened on the forum with either the </> or "running man" icons. The message windows on this forum will reformat text and insert html tags so that pasted code may not run properly.
A caveat with Proc Tabulate: by default any records with missing values for any class variable (grouping or categorical) will remove that entire record from the report.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.