ODS and Base Reporting

Build reports by using ODS to create HTML, PDF, RTF, Excel, text reports and more!
BookmarkSubscribeRSS Feed
Thomas_mp
Obsidian | Level 7

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

 

9 REPLIES 9
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller
Thomas_mp
Obsidian | Level 7

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

 

 

Reeza
Super User
There's a good macro here that you can use and pipe the results directly to Word or Excel as desired using ODS as illustrated in PaigeMiller's answer.

https://communities.sas.com/t5/SAS-Communities-Library/Demographic-Table-and-Subgroup-Summary-Macro-...

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Reeza
Super User
Except that's still the standard for journal publications and reports...
PaigeMiller
Diamond | Level 26

@Reeza wrote:
Except that's still the standard for journal publications and reports...

Not stated by the OP as a requirement.

--
Paige Miller
Thomas_mp
Obsidian | Level 7
Thank you again Reeza,
His is the 3 occasion you take time to answer my questions.
This works, but for now I will continue using  STATA; it produces the output in a way I can easily manipulate for papers in my discipline (finances).
But thank you for your time,

Tomas

ballardw
Super User

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.

 

 

Thomas_mp
Obsidian | Level 7
Thank you Ballard. 

Your code helps to read the output, but now I will continue using  STATA; i find it easier and more"flexible".
But thank you for your time,

Tomas

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 2354 views
  • 5 likes
  • 4 in conversation