BookmarkSubscribeRSS Feed
anandbillava
Fluorite | Level 6
Is there any way to check are there any SAS catalogs and datasets present in a folder ?
11 REPLIES 11
andreas_lds
Jade | Level 19
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]
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You can use the FILEEXIST function to test if a directory/folder path exists.

Scott Barry
SBBWorks, Inc.
anandbillava
Fluorite | Level 6
Fileexisits can be used when you want to check a specific dataset or catalog.
I think checking for an entry in vmember is ideal.
anandbillava
Fluorite | Level 6
Any body knows how to check in which platform the dataset or the catalogs are created ?
Cynthia_sas
SAS Super FREQ
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
anandbillava
Fluorite | Level 6
Does anybody know why querying vcolumns table is very slow.
ArtC
Rhodochrosite | Level 12
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.
Peter_C
Rhodochrosite | Level 12
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
ArtC
Rhodochrosite | Level 12
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.
SASKiwi
PROC Star
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.
SASKiwi
PROC Star
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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 1924 views
  • 0 likes
  • 7 in conversation