List all Catalogs within a Library - sas

As the title says: Is there a way to display all catalogs within a library like WORK using a PROC statement (or something similar)?
I tried PROC catalog and PROC datasets memtype=catalog but none of these seem to offer this option.
I am using SAS EG and indeed there is (at least in EG) a GUI way to list them via TOOLS -> Catalog and Formats Explorer and then one can browse through the libraries. However, I'd like to use a non-GUI approach and just couldn't find one so far.

You can use dictionary.catalogs, read more you can here. For example, to display catalogs from lib Work you can use this proc sql:
proc sql;
title 'Subset of the DICTIONARY.CATALOGS Table';
title2 'Rows with Library Name WORK';
select * from dictionary.catalogs
where libname ='WORK';
quit;

You can capture the ODS output portion of Proc CONTENTS that lists catalog members. The data= option will be {the libname}._ALL_
ods results off;
ods output contents.members=work.catalogs;
proc contents data=sashelp._all_ mt=catalog;
run;
quit;
ods results on;

Related

Can I use wildcards in dataset names for PROC CONTENTS?

On the SAS server we have a library that contains thousands of datasets. I want to catalog the contents of a subset of these, all of which have names that begin with "prov". Can I use a wildcard to specify this?
I tried:
PROC CONTENTS DATA=library.prov*;
RUN;
But that just produces a log with this error message:
ERROR: File LIBRARY.PROV.DATA does not exist.
I also tried library.prov%, and that gave the same error.
There are over 100 datasets that start with "prov" so I really don't want to have to do them one at a time. Any ideas?
Depending on what information you want that the CONTENTS procedure produces you could just use the DICTIONARY metadata views.
proc sql ;
create table want as
select *
from dictionary.columns
where libname = 'LIBREF'
and memname like 'PROV%'
;
quit;
Use a WHERE data set option.
proc contents data=sashelp._all_ noprint out=class(where=(memname like 'CLASS%'));
run;
When you specify the keyword _ALL_ in the PROC CONTENTS statement, the step displays a list of all the SAS files that are in the specified SAS library.
Example :
PROC CONTENTS DATA=libref._ALL_ NODS;
RUN;
But to open only the datasets that begin with prov you can use the SQL and add CONTAINS to WHERE e.g:
proc sql ;
create table mytables as
select *
from dictionary.tables
where libname = 'WORK'
order by memname ;
quit ;
Now just run:
PROC CONTENTS DATA mytables;
RUN;
I may be using a different version of SAS check if you have the library SASHELP if so try this based on my note in your comment on the previous response you may see that this works out for you:
proc sql outobs=100;
create table see as
select distinct libname,memname,crdate,modate from sashelp.vtable
where libname='LIBRARY' and memname like 'PROV%'
order by memname;
quit;

SAS ODS Query/Statement print along with it's output

SAS EG
Is there any way I can print the query/statement used to get the output, along with the output, using SAS ODS?
Suppose,
ods pdf file=pdfile;
proc sql;
select a.*
from tab1 a inner join tab2 b
on a.something=b.something
where <>
having <>;
quit;
ods _all_ close;
this would print the OUTPUT generated from the above query. But can I also get the query printed via the ods pdf along with the output?
There's no automatic way to redirect the log that I'm aware of.
There are a few ways to get what you want, however.
First off, if you are able to use Jupytr, SAS has plugins to enable that to work with SAS, and then you can simply write in the notebook and run the code, and the results appear with your code just as you want. See Chris Hemedinger's blog post on the subject for more details.
Second, SAS Studio will support a notebook-style interface probably with the next major revision (I believe version 5.0) which will release late next year. So similarly, you would put your code and get your output in the same windows.
Finally, the third option is to do as Reeza suggested - write to a log file, then print that to the output. It's messy but possible.
Here's an example of the latter. I don't make any effort to clean it up, note, you'd probably want to remove the logging related to PROC PRINTTO and the otehr notes (or turn on NONOTE).
ods pdf file="c:\temp\test.pdf";
filename logfile temp;
proc printto log=logfile;
run;
proc sql;
select * from sashelp.class;
quit;
proc printto;
run;
data _null_;
infile logfile;
input #1 #;
call execute(cats('ods text="',trim(_infile_),'";'));
run;
ods _all_ close;

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.

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.

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.