SAS RobustReg Procedure output parameter estimates [duplicate] - sas

Running complex procs such as PROC REG or PROC GLM, there are often tables that are produced in the output window describing the results of the regression, in addition to the output datasets produced using OUT or OUTPUT options.
How can I output those tables to SAS datasets?
For example, given the first SAS example in PROC REG (on the documentation page), how can I output the Goodness of Fit Statistics (such as the R-Squared)?

In order to identify possible output datasets, SAS provides the ods trace statement. This asks SAS to write to the log the name (and some details) of each data table it writes to the output. In most cases, this can be saved to a dataset via ods output.
For example, in the SAS example referred to in the question, you could write:
ods trace on;
proc reg data=baseball;
id name team league;
model logSalary = no_hits no_runs no_rbi no_bb yr_major cr_hits;
run;
ods trace off;
That would report in the log that "FitStatistics" is the name of the output object you want. Then you write:
ods output FitStatistics=fitds;
proc reg data=baseball;
id name team league;
model logSalary = no_hits no_runs no_rbi no_bb yr_major cr_hits;
run;
and it will output the fitds dataset.
ODS Trace is only needed for the purpose of determining the name of the table of course - once you know the name of the table you need, you can simply use that name with ods output in the future.
You also frequently can find the list of the table names in the documentation; for example, PROC REG places them here.
ODS Output may be placed any location before the run statement (as it is a global statement); a common location is immediately before run. My personal preference is to put it before the proc as it is a global statement, but there is some disagreement with that approach.

Related

How to get SAS tables sizes and last usage time in library

Good day!
I need a list of libraries-tables on a SAS server with a size of each table and last time, when it was open/used.
I'm not very familiar with SAS, so I don't even know where would I start searching :(
I assume, that there is some simple solution, maybe a proc of some sort, that may help...
You can use proc contents to access metadata about a library in SAS, for example using the sashelp library:
proc contents data = sashelp._ALL_ NODS;
run;
sashelp is the library you are refencing. By specifying _ALL_ you ask SAS for data about all the files in this library (by choosing a singular file such as sashelp.ztc you can get information on jut one file).
This will give you a lot of information, so by using the NODS statement you can suppress the output to give you less detail. The above code will give you the number of files, their type, the level, the file size, and the data they were last modified.
If you want to output this information to a dataset, you have to use the ODS output system with the correct ods table name, in this case it is Members. Furthermore, if you're looking for datasets in particular then you can filter the output with a where= statement:
ods output Members = test (where = (memtype = "DATA"));
proc contents data = work._ALL_ NODS noprint;
run;
ods listing; /* change back to listing output*/

How do I see what output options are available in my proc?

Running complex procs such as PROC REG or PROC GLM, there are often tables that are produced in the output window describing the results of the regression, in addition to the output datasets produced using OUT or OUTPUT options.
How can I output those tables to SAS datasets?
For example, given the first SAS example in PROC REG (on the documentation page), how can I output the Goodness of Fit Statistics (such as the R-Squared)?
In order to identify possible output datasets, SAS provides the ods trace statement. This asks SAS to write to the log the name (and some details) of each data table it writes to the output. In most cases, this can be saved to a dataset via ods output.
For example, in the SAS example referred to in the question, you could write:
ods trace on;
proc reg data=baseball;
id name team league;
model logSalary = no_hits no_runs no_rbi no_bb yr_major cr_hits;
run;
ods trace off;
That would report in the log that "FitStatistics" is the name of the output object you want. Then you write:
ods output FitStatistics=fitds;
proc reg data=baseball;
id name team league;
model logSalary = no_hits no_runs no_rbi no_bb yr_major cr_hits;
run;
and it will output the fitds dataset.
ODS Trace is only needed for the purpose of determining the name of the table of course - once you know the name of the table you need, you can simply use that name with ods output in the future.
You also frequently can find the list of the table names in the documentation; for example, PROC REG places them here.
ODS Output may be placed any location before the run statement (as it is a global statement); a common location is immediately before run. My personal preference is to put it before the proc as it is a global statement, but there is some disagreement with that approach.

Output to new data set

Suppose that I have a model and I want to output the studentized residuals, leverages, Cook's Distance and the DFFITS statistics from my regression model to a new data set. How would I do this?
Answering as a general question of how do I get certain pieces of output from a proc to a dataset, you will want to look at ODS TRACE.
ods trace on;
proc reg <stuff>;
<stuff>;
run;
ods trace off;
Now, look at the log, and see what different output options you have. All of the different things that go to the screen will be here, plus additional tables sometimes that don't go to any output window by default. Find the name for the tables you want data from, and then direct them to an ods output statement.
ods output <name>=<datasetname>;
proc reg <stuff>;
<stuff>;
run;
ods output close;
You can specify multiple names and multiple output datasets, assuming you want more than one thing.

How to export selected p-values to the table in SAS?

I'm trying to write a program in SAS that supports decision-making process in selecting the best formula of linear regression model. I even had one but in R environment. Now I have to implement it in SAS. The final result should be a dataset with each line decribing different regression formulas i.e. names of explanatory variables, R-squared, p-values for different statistical tests, etc.
As an example, one of the tests is Durbin-Watson test for autocorrelation. My goal is to insert a p-value into the table I've mentioned. I use the code:
proc reg data=indata outest=outdata EDF ridge=0 OUTVIF;
model PKB = PK INV SI / DW;
run;
quit;
And as a result I get in the output window:
Durbin-Watson Statistics
Order DW Pr < DW Pr > DW
1 1.2512 0.0038 0.9962
I want to insert those p-values directly into the SAS table. I tried to find an answer in the SAS OnlineDoc and on the forum but with no success.
ODS OUTPUT is the best way to get information that you can print to the screen into datasets. Use ODS TRACE ON; before your code, run it, then inspect the log; see what table name matches what you're looking for. Then use ODS OUTPUT <tablename>=<datasetname>.
For example, in this PROC FREQ, I see ONEWAYFREQS is the table I want.
ods trace on;
proc freq data=sashelp.class;
var age;
run;
ods trace off;
So I use ODS OUTPUT:
ods output onewayfreqs=ages;
proc freq data=sashelp.class;
table age;
run;
ods output close;
and get a nice dataset. (ODS TRACE is not necessary if you know the name of the table you're looking for.)

SAS Proc UCM output breakpoints

I have a timeseries dataset in SAS and I am running this data through the UCM procedure to identify signficiant structural breakpoints in the timeseries (changes in the expected mean).
My code is as follows:
proc ucm data=temp;
by source;
id date interval=month;
model baseload;
irregular;
level checkbreak;
run;
The level checkbreak statement above is printed in the SAS output window in the section labeled 'outlier summary', but I need the output in a dataset. The 'outest' statement only works for the 'estimate' statement and not the level statement in proc UCM. Does anyone know know if it is possible to write this section out to a dataset?
You can access the OutlierSummary table using SAS's ODS system.
Read about it here:
http://support.sas.com/documentation/cdl/en/etsug/60372/HTML/default/viewer.htm#etsug_ucm_sect034.htm