DATA Step, Macro, Functions and more

How to check catalogs and datasets present in a folder ?

Reply
Contributor
Posts: 72

How to check catalogs and datasets present in a folder ?

Is there any way to check are there any SAS catalogs and datasets present in a folder ?
Super Contributor
Posts: 345

Re: How to check catalogs and datasets present in a folder ?

Posted in reply to anandbillava
Use the folder in an libname statement, then check sashelp.vmember.

Untested:

[pre]libname check "path";

proc sql print;
select count(*) as CatalogCount
from sashelp.vmember
where libname = "CHECK" and memtype = "CATALOG";
select count(*) as DatasetCount
from sashelp.vmember
where libname = "CHECK" and memtype = "DATA";
quit;

libname check clear;[/pre]
Super Contributor
Super Contributor
Posts: 3,174

Re: How to check catalogs and datasets present in a folder ?

Posted in reply to andreas_lds
You can use the FILEEXIST function to test if a directory/folder path exists.

Scott Barry
SBBWorks, Inc.
Contributor
Posts: 72

Re: How to check catalogs and datasets present in a folder ?

Fileexisits can be used when you want to check a specific dataset or catalog.
I think checking for an entry in vmember is ideal.
Contributor
Posts: 72

Re: How to check catalogs and datasets present in a folder ?

Posted in reply to anandbillava
Any body knows how to check in which platform the dataset or the catalogs are created ?
SAS Super FREQ
Posts: 8,868

Re: How to check catalogs and datasets present in a folder ?

Posted in reply to anandbillava
Hi:
That information is contained in either the Engine/Host output object from PROC CONTENTS, or in the DATAREPNAME variable from SASHELP.VTABLE or the DICTIONARY. equivalent of SASHELP.VTABLE. To create a SAS dataset from an ODS output object, use the ODS OUTPUT statement. To create a SAS dataset from a query against the SASHELP or DICTIONARY dataset, use SQL techniques, as shown previously.

User group papers that outline how to use SASHELP.VCOLUMNS or DICTIONARY.COLUMNS will probably also have information on these tables as well.

cynthia
Contributor
Posts: 72

Re: How to check catalogs and datasets present in a folder ?

Posted in reply to Cynthia_sas
Does anybody know why querying vcolumns table is very slow.
Valued Guide
Posts: 634

Re: How to check catalogs and datasets present in a folder ?

Posted in reply to anandbillava
SASHELP.VCOLUMNS is a VIEW and as such is built when requested. Since it contains one row for every variable, in every table, in every library available to SAS, it can take awhile. PROC CONTENTS with an OUT= option for a specific libref is usually faster.
[pre]
proc contents data=mylib._all_ out=cont;
run;
[/pre]
See today's tip of the Day on sasCommunity.org.
Valued Guide
Posts: 2,177

Re: How to check catalogs and datasets present in a folder ?

seems a bit cheeky to add to an ArtC posting but feel it is worth offering PROC SQL.
An SQL where clause testing just LIBNAME will be very much faster than the equivalent data step.
In sql sashelp.vcolumn should provide information more quickly if the sql has a WHERE clause explicitly restricting the query to named libraries. If functions or expressions in the where clause can only be satisfied by reading table information (like nobs, last modified date or column format) then sql will be just as slow as the data step.

peterC
Valued Guide
Posts: 634

Re: How to check catalogs and datasets present in a folder ?

Good point Peter. In the DATA step the WHERE is applied after the view instructions have been executed (even a WHERE= on the SET statement), however in a SQL step, the WHERE is applied as the table is being built from the view. Thus using the view in a SQL step, with a WHERE, can result in huge savings.
Super User
Posts: 3,260

Re: How to check catalogs and datasets present in a folder ?

From personal experience the fastest way to get info on SAS files is to use the DICTIONARY tables directly in SQL. For example:

proc sql noprint;
select name into :var_name separated by ' ' from dictionary.columns
where upcase(libname)='SASHELP' and upcase(memname)='CLASS';
quit;
%put &var_name;

This example builds a variable list for the selected table and stores it into a macro variable. It is a very handy technique that can be used for a variety of purposes.
Super User
Posts: 3,260

Re: How to check catalogs and datasets present in a folder ?

The following example is closer to what you want:

proc sql noprint;
select memname into :mem_list separated by ' ' from dictionary.members
where upcase(libname)='SASHELP' ;
quit;
%put &mem_list;

You can limit the types of SAS files to search on by using MEMTYPE in the WHERE clause.
Ask a Question
Discussion stats
  • 11 replies
  • 263 views
  • 0 likes
  • 7 in conversation