Help using Base SAS procedures

Get a list of dataset names in a directory/library

Reply
Frequent Contributor
Posts: 77

Get a list of dataset names in a directory/library

proc contents data=a._all_ out=a1 memtype=data noprint;
run;

a1 has all datasets info down to variable level. I know I can use another proc sql(see code below) to get the list of dataset names. But I still want to know how to do it in proc contents or any other procedures if this is possible.


proc sql;
select distinct memname
from a1
; quit;
Super Contributor
Super Contributor
Posts: 3,174

Re: Get a list of dataset names in a directory/library

PROC DATASETS provides a list. Also, consider reviewing the PROC CONTENTS option NODS, when using the DATA=._ALL_ parameter.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

proc contents member list site:sas.com
Frequent Contributor
Posts: 77

Re: Get a list of dataset names in a directory/library

I did use NODS option, but it returns a1 with 0 observation.

proc contents data=viewstr._all_ out=a1 memtype=data nods;
run;
Respected Advisor
Posts: 3,777

Re: Get a list of dataset names in a directory/library

Try this...

[pre]
ods output Members=Members;
proc datasets library=work memtype=data;
run;
quit;
[/pre]
Frequent Contributor
Posts: 77

Re: Get a list of dataset names in a directory/library

I want to output the list to a dataset for later manipulation. There is no out option in proc datasets.
SAS Super FREQ
Posts: 8,740

Re: Get a list of dataset names in a directory/library

But, ODS OUTPUT will create an output dataset from the output object MEMBERS. If you use ODS TRACE ON/ODS TRACE OFF around PROC DATASETS, you will see the following output:
[pre]
893 ods trace on;
894 proc datasets library=work memtype=data;

Output Added:
-------------
Name: Directory
Label: Directory Information
Template: Base.Datasets.Directory
Path: Datasets.Directory
-------------
Directory

Libref WORK
Engine V9
Physical Name C:\DOCUME~1\Temp\SAS Temporary Files\_TD5040
Filename C:\DOCUME~1\Temp\SAS Temporary Files\_TD5040

Output Added:
-------------
Name: Members
Label: Library Members
Template: Base.Datasets.Members
Path: Datasets.Members
-------------

Member File
# Name Type Size Last Modified

1 MEMBERS DATA 5120 22Nov10:15:50:19
2 PRDSALE DATA 50176 22Nov10:10:57:31
3 REPORT_DATA DATA 209920 22Nov10:08:45:15
895 run;

896 quit;

NOTE: PROCEDURE DATASETS used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds

897 ods trace off;
[/pre]

The "Output Added" means that the procedure created an "output object" and it is this ODS output object that gets routed to ODS destinations. Not all ODS destinations are report destinations like LISTING, RTF and PDF and HTML. ODS DOCUMENT and ODS OUTPUT are destinations that are NOT report destinations. ODS OUTPUT is the destination that creates output datasets.

That means that you can write the output object "MEMBERS" to a dataset with the ODS OUTPUT statement, as shown in data _null_'s code. One of the great features of the Output Delivery System is the fact that if a procedure creates an output object you can make a dataset from that output object -- EVEN IF the dataset itself does not support or have an OUT= option or OUTPUT statement.

Check it out. There are a lot of good papers and examples out there on the use of ODS OUTPUT.

cynthia
Respected Advisor
Posts: 3,777

Re: Get a list of dataset names in a directory/library

Yes, that is why I used ODS OUTPUT to create data set MEMBERS.
Ask a Question
Discussion stats
  • 6 replies
  • 4439 views
  • 0 likes
  • 4 in conversation