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

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 897 views
  • 0 likes
  • 2 in conversation