Help using Base SAS procedures

Output dataset of proc univariate stats for multiple variables

Reply
Contributor
Posts: 20

Output dataset of proc univariate stats for multiple variables

The current code...

proc univariate data = my_input_dataset;
var age weight height;
output out = my_output_dataset
median = median
mean = mean
mode = mode
;
run;

So this appears to output the stats for "age", but then overwrites with the stats for "weight", and finally "height". So I only end up with one row containing the stats for the most recent variable.

Can the univariate procedure create a dataset with the stats for all of these variables (ie, without having to throw in some data steps and loop, etc)? In which case, is there a way to throw in the variable name to distinguish the rows?
SAS Super FREQ
Posts: 8,744

Re: Output dataset of proc univariate stats for multiple variables

Hi:
You have 2 choices:
1) Use Univariate internal OUTPUT syntax to name the variables listed in your VAR statement or
2) Use ODS OUTPUT syntax to get the "BASICMEASURES" output object that will contain all the info for the variables listed in the VAR statement.

cynthia
[pre]
** 1) Use Univariate OUTPUT statement to create multiple variables;
ods trace on /label;
proc univariate data = sashelp.class;
var age weight height;
output out = my_output_dataset
median =medage medwt medht
mean =mnage mnwt mnht
mode =modage modwt modht ;
run;
ods trace off;

ods listing;
proc print data=my_output_dataset;
title '1) Using Internal OUTPUT statement';
run;

** 2) use ODS OUTPUT statement;
ods output basicmeasures=work.all_basic;
proc univariate data = sashelp.class;
var age weight height;
run;

proc print data=work.all_basic;
title '2) Using ODS OUTPUT';
run;
[/pre]
Ask a Question
Discussion stats
  • 1 reply
  • 387 views
  • 0 likes
  • 2 in conversation