0%

Capturing statistic tables from SAS procedure - SASlearner

As a new SAS user, a common question that is always asked and searched on google is: how can I get the statistic into a table?

In addition to reading the corresponding procedure reference in the official documentation, I recommend using the ods trace on to find the stat table names, and then extract any table you want. Here is the regression analysis of the sashelp.cars dataset, let's see how to get the stat tables.

ods trace on;                           /* write ODS table names to log */
proc reg data=sashelp.cars plots=none;
   model Horsepower = EngineSize Weight;
quit;
ods trace off;                          /* stop writing to log */

The logs you can see in SAS are as follows:

Output Added:
-------------
Name:       NObs
Label:      Number of Observations
Template:   Stat.Reg.NObs
Path:       Reg.MODEL1.Fit.Horsepower.NObs
-------------

Output Added:
-------------
Name:       ANOVA
Label:      Analysis of Variance
Template:   Stat.REG.ANOVA
Path:       Reg.MODEL1.Fit.Horsepower.ANOVA
-------------

Output Added:
-------------
Name:       FitStatistics
Label:      Fit Statistics
Template:   Stat.REG.FitStatistics
Path:       Reg.MODEL1.Fit.Horsepower.FitStatistics
-------------

Output Added:
-------------
Name:       ParameterEstimates
Label:      Parameter Estimates
Template:   Stat.REG.ParameterEstimates
Path:       Reg.MODEL1.Fit.Horsepower.ParameterEstimates

By looking at the output you can find each stat table name, like ParameterEstimates. That means you can extract it by adding the ods output ParameterEstimates=rst statement to store the table in the rst dataset, as follows:

proc reg data=sashelp.cars plots=none;  /* same procedure call */
   model Horsepower = EngineSize Weight;
   ods output ParameterEstimates=rst;        /* the data set name is 'rst' */
quit;

Multiple stat tables can be stored in one ods output statement. For example below statement stores both ParameterEstimates table and ANOVA table at the same time.

proc reg data=sashelp.cars plots=none;
   model Horsepower = EngineSize Weight;
   ods output ParameterEstimates=parms ANOVA=anvar;
quit;

And then if you want to create a macro variable that contains the value of certain statistic, such as slope for EngineSize:

data _null_;
    set rst;
    if variable="EngineSize" then 
        call symputx("slope1", estimate);
run;
%put &=slope1;

Several procedures provide an alternative option for createing an output similar to the ods ouput mentioned above. For instance, the outest option in the proc reg procedure.

proc reg data=sashelp.cars noprint outest=rst2 rsquare; /* statistics in 'rst2' */
   model Horsepower = EngineSize Weight;
quit;

So you'd better to check the SAS documentation to see if this procedure you use.


All of the above is referred to the following articles:

ODS OUTPUT: Store any statistic created by any SAS procedure
Find the ODS table names produced by any SAS procedure