Alex
Alex

Reputation: 3413

Output PROC MEANS to a file/SAS data table

In PROC FREQ procedure we can specify an output table in the following terms:

    Proc Freq
        DATA=LIB.TABLE_IN
        ORDER=FREQ;

        TABLES FIELD / MISSING OUT = LIB.TABLE_OUT; /* outputs to a SAS data table */
    RUN;

How could we do the same with PROC MEANS procedure?

proc means data=LIB.TABLE_IN n nmiss;

Thanks for helping!

Upvotes: 1

Views: 37404

Answers (3)

Frank Song
Frank Song

Reputation: 1

If you need only N, MIN,MAX, MEAN, and STD, the simple lines below can produce a nice table, here named 'sumTab'. however, if you add NMISS and others, it will be in a wide format.

    proc means data = X ; 
        var _numeric_;
        output out = sumTab ; 
    run;

Upvotes: 0

user667489
user667489

Reputation: 9569

Nearly anything you can do with proc means that produces output in the listing area can also be produced via proc summary as an output dataset, albeit sometimes with slightly different syntax and in a different output format. E.g. this produces the same information as your example, but in a wide table rather than a long one:

proc summary data=sashelp.class;
  var _numeric_;
  output out = my_summary n= nmiss= /autoname;
run;

Upvotes: 1

Joe
Joe

Reputation: 63424

Two ways. The output statement sends output to a dataset; you also can use ods output as you can with any proc.

proc means data=sashelp.class;
  class sex;
  types sex;
  var height weight;
  output out=class_means mean= sum= /autoname;
run;

To use ods output you need to know the name of the table produced by the proc. You can use ODS TRACE to find out what the name of the table is.

ods trace on;
proc means data=sashelp.class;
  class sex;
  types sex;
  var height weight;
run;
ods trace off;

You'll find it's called summary. So you add ods output statement like so:

ods output summary=class_means_ods;
proc means data=sashelp.class;
  class sex;
  types sex;
  var height weight;
  output out=class_means mean= sum= /autoname;
run;
ods output close;

Finally, proc means has an option after I think 9.3 (or maybe 9.22) stackodsoutput which changes the format of the resulting dataset to be more tabular, which may be helpful for you.

ods output summary=class_means_ods;
proc means data=sashelp.class stackodsoutput;
  class sex;
  types sex;
  var height weight;
  output out=class_means mean= sum= /autoname;
run;
ods output close;

Upvotes: 2

Related Questions