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 Innovate 2025: Call for Content! Submit your proposals before Sept 16. Accepted presenters get amazing perks to attend the conference!
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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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