BookmarkSubscribeRSS Feed
PeterVanDePol
Calcite | Level 5

The SAS knowledge base provides useful examples how to retrieve several kinds of metadata

One that attracted my attention was the program to list all libraries and their associated directory or database schema  

Since my requirement is to to list all libraries for all users and groups, I enhanced the program a little to loop through all logins

and get all associated libraries (both Oracle databases and/or base directories) for each login. See code below.

The result of running this program is a small list of connections to Oracle/ODBC libraries

Since we have several SAS users with access to base directories, I would have expected to see them in this list too

Any ideas or suggestions?

***my program***

data logins_libraries;

  length liburi loguri upasnuri uri0 $256

         name $128

         loginobjid identobjid type id $17

         libref engine $8

         path mdschemaname schema $256;

  keep loginobjid identobjid name libref engine path mdschemaname schema;

  call missing(liburi,loguri, upasnuri,name,engine,libref,loginobjid,identobjid);

  nlogobj=1;

  logrc=metadata_getnobj("omsobj:Login?@Id contains '.'",nlogobj,loguri);

  if logrc<=0 then put "NOTE: rc=" logrc

     "There are no Logins defined in this repository"

     " or there was an error reading the repository.";

  do while(logrc>0);

    rc=metadata_getattr(loguri,'Id',loginobjid);

    n0=1;

    airc=metadata_getnasn(loguri,"AssociatedIdentity",n0,uri0);

    if airc<=0 then put "NOTE: rc=" airc

      "There is no Person or Group associated with the " loginobjid "Login ID.";

    else do;

      arc=metadata_resolve(uri0,IdentType,IdentId);

      rc=metadata_getattr(uri0,'Id',identobjid);

    end;

    nlibobj=1;

    librc=metadata_getnasn(loguri,'Libraries',nlibobj,liburi);

    do while (librc>0);

      rc=metadata_getattr(liburi,'Name',name);

      rc=metadata_getattr(liburi,'Engine',engine);

      rc=metadata_getattr(liburi,'Libref',libref);

      n=1;

      uprc=metadata_getnasn(liburi,'UsingPackages',n,upasnuri);

      if uprc > 0 then do;

        call missing(type,id,path,mdschemaname,schema);

        rc=metadata_resolve(upasnuri,type,id);

        if type='Directory' then do;

          rc=metadata_getattr(upasnuri,'DirectoryName',path);

          output;

        end;

        else

          if type='DatabaseSchema' then do;

            rc=metadata_getattr(upasnuri,'Name',mdschemaname);

            rc=metadata_getattr(upasnuri,'SchemaName',schema);

            output;

          end;

        n+1;

        uprc=metadata_getnasn(liburi,'UsingPackages',n,upasnuri);

      end; /* if uprc > 0 */

      nlibobj+1;

      librc=metadata_getnasn(loguri,'Libraries',nlibobj,liburi);

    end; /* do while (librc>0) */

    nlogobj+1;

    logrc=metadata_getnobj("omsobj:Login?@Id contains '.'",nlogobj,loguri);

  end; /* do while (logrc>0) */

run;

proc sort data=logins_libraries NODUPRECS;

run;

2 REPLIES 2
ChrisHemedinger
Community Manager

Your program reports on the information that is stored in the SAS metadata server, but does not include the "physical" libraries that might be actually assigned in the user's session.

For that list, you can run something like:

proc sql;
create table libs as
 
select * from sashelp.vlibnam;
quit;

This will yield a different set of columns that relate to the libnames and engines and paths.  Some might overlap with the list you get from metadata, so you'll need to join with that list by a common key -- like the LIBNAME -- to present the complete picture.

Chris

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
PeterVanDePol
Calcite | Level 5

Hi Chris,

Thanks for your answer.

What puzzles me is that all libraries (both oracle and base) do show up when the logins are skipped from query.

That is, the query is run without the outer login loop.

It seems that the link between login/user and physical base directory(ies) is somewhere is not present...

Peter

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 2 replies
  • 1318 views
  • 0 likes
  • 2 in conversation