How do I see what output options are available in my proc? - 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*/

SAS RobustReg Procedure output parameter estimates [duplicate]

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.)

Clustermembers on SPDS 4.3

I am working with clustered datasets on SPDS 4.3.
I want to generate a list of the members for each cluster.
I found two possibilities to get the information I am looking for.
Either by using PROC CONTENTS and have a look on field "Cluster members are" or by using PROC SPDO like this:
PROC SPDO LIBRARY=P30C033;
CLUSTER LIST LD_LIQ_CLUS_Customer;
QUIT;
In both cases I get the information in form of a report.
But I would like to get the information in form of a dataset.
I already tried out= and out2= on PROC CONTENTS, but dont get the desired output.
I also searchd for options to PROC SPDO CLUSTER LIST, but with no result.
Thx in advance
MiKe
As a generic answer for any PROC, you can use ODS OUTPUT to get the dataset even if you can't use OUT= .
Add ODS TRACE ON; before the proc runs (and ODS TRACE OFF after it). It should give you some results in the log telling you what the output is named; you can then use ODS OUTPUT to get the results.
For example, with PROC CONTENTS, run:
ods trace on;
proc contents data=sashelp.class;
run;
ods trace off;
Mabe you see that the VARIABLES table looks interesting to you. So run:
ods output Variables=sasvars;
proc contents data=sashelp.class;
run;
ods output close;
ODS TRACE is not needed if you already know the name of the output portion, of course.
You can use ODS OUTPUT CLUSTERLIST= as shown in the below code example:
ods noresults;
ods output clusterlist=WORK.CLUSTER_MEMS;
proc spdo lib=SPDSLIB;
cluster list CLUSTER1;
cluster list CLUSTER2;
/* ... */
cluster list CLUSTERN;
quit;
ods output close;
ods results;
This allows you to capture one or multiple clusters' members into a single data set.
You can also capture cluster members to separate data sets using OUT= option:
proc spdo lib=SPDSLIB;
cluster list CLUSTER1 out=CLUSTER1_MEMBERS;
cluster list CLUSTER2 out=CLUSTER2_MEMBERS;
/* ... */
cluster list CLUSTERN out=CLUSTERN_MEMBERS;
quit;
For more on this topic see my recent blog post How to retrieve contents of a SASĀ® Scalable Performance Data Server library.