DATA Step, Macro, Functions and more

Finding Libname of a dataset

Reply
Super Contributor
Posts: 625

Finding Libname of a dataset

In my site we've multiple libraries and multiple datasets. If I want to find the library for some particular dataset, I manually looking at each of library to find if the dataset which I'm looking for is available. Is there any way to find the library of some particular dataset programmatically?

 

Regular Contributor
Posts: 182

Re: Finding Libname of a dataset

Depends on the OS.  You're more likely to find it by searching withing Windows Explorer, grep (linux/unix) or something like those.  You certainly can use proc datasets to see all the datasets in a particular library, though.

Contributor
Posts: 28

Re: Finding Libname of a dataset

a long time ago, i find table sizes for each table in each predefined library.  i found a bit of starter code that i then modified.  this is what i am currently using:

 

proc sql;
create table VATableSize as
select libname, memname as TableName, nobs, filesize, obslen, nobs*obslen as Bytes, crdate, modate
from dictionary.tables
where NOT(libname IN ('MAPS','MAPSGFK','MAPSSAS','SAMPSIO','SASHELP', 'STPSAMP', 'WORK'))
ORDER BY FileSize Desc;
quit;

 

 

NOTE:  i run this in a program a few times a day, and dump the output to SAS Visual Analytics so that i can kinda keep tabs on various users data storage tendencies.

Valued Guide
Posts: 529

Re: Finding Libname of a dataset

You can query sashelp.vtable:

 

proc sql;
   select LibName, MemName
      from sashelp.vtable
         where MemName = 'CLASS'
   ;
quit;

The name of the Dataset must be in upcase.

Super User
Posts: 9,941

Re: Finding Libname of a dataset

If you want to find the directory where dataset MYDATA is located, do this on UNIX:

find / -name mydata.sas7bdat

It's best to run this command as the superuser, because you'll get lots of messages about directories where you lack permissions otherwise.

Now, if you have a defined base directory for all your libraries, you can start there:

find /sasbase -name mydata.sas7bdat

And you'll only need a userid that has read/execute permissions on all the subdirectories there.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 9,941

Re: Finding Libname of a dataset

The problem with the dictionary.tables ( @utrocketengineer) and sashelp.vtable ( @andreas_lds) approaches is that they only work on currently assigned libraries. They won't find any .sas7bdat files in directories where you do not have an active libname on.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Regular Contributor
Posts: 182

Re: Finding Libname of a dataset

Posted in reply to KurtBremser

The OP did say 'libraries' and not 'directories', so I think the solutions offered will work.

Ask a Question
Discussion stats
  • 6 replies
  • 119 views
  • 4 likes
  • 5 in conversation