0

Is it possible to get the list of libraries assigned (pre & non-pre assigned) to an application server in SAS Metadata?

I can use dictionary.libnames but it lists only pre-assigned libraries.

athresh
  • 553
  • 6
  • 11
  • 24
  • So you want to know what libraries are _available_ in metadata, right? Not what are actually currently active. – Joe Jul 11 '21 at 13:46
  • I do not want the list of libraries available in metadata, but the ones that are assigned to an application server. – athresh Jul 12 '21 at 11:19
  • If they're actively assigned, then they should be in `dictionary.libnames` - My current server has nearly no pre-assigned libraries, but finds tons in `dictionary.libnames`. – Joe Jul 12 '21 at 14:30
  • There's a macro for this, and many others, in the SASjs/core library - https://core.sasjs.io/mm__getlibs_8sas.html – Allan Bowe Jul 13 '21 at 06:53

3 Answers3

1

Assuming you want to just find out all of the available libraries, and have an account (such as sasadm@saspw) which can see them, then you should be able to iterate using the metadata_getnobj function. Something like this:

 nobj=metadata_getnobj("omsobj:SASLibrary?@Id contains '.'",n,uri);

The example from the documentation otherwise should match what you're doing:

data _null_;
    length uri $256;
    nobj=0;
    n=1;
   
    /* Determine how many machine objects are in this repository. */

    nobj=metadata_getnobj("omsobj:SASLibrary?@Id contains '.'",n,uri);
    put nobj=;   /* Number of machine objects found. */
    put uri=;    /* URI of the first machine object. */

run;

You could then iterate through those, with a do n = 1 by 1 until (n lt 0); loop or similar, and use the metadata_getattr function to obtain the information you want about each uri. You could look at this SAS Communities question for example; the code there should work (their issue was not the code, but their machine setup). Something like this:

data _null_;
    length uri $256;
    nobj=0;
    n=1;
    uri=' ';
    length name engine libref $256;
    call missing(of name engine libref);
    nobj=metadata_getnobj("omsobj:SASLibrary?@Id contains '.'",n,uri);
    /* Determine how many machine objects are in this repository. */
    do n = 1 to nobj;
      nobj=metadata_getnobj("omsobj:SASLibrary?@Id contains '.'",n,uri);
      rc=metadata_getattr(uri,'Name',name);
      rc=metadata_getattr(uri,'Engine',engine);
      rc=metadata_getattr(uri,'Libref',libref);
      put name= engine= libref=;
    end;
run;

This would only include metadata libraries - not libraries that are active, but defined only in SAS code. For the latter, you do need to use dictionary.libnames.

Joe
  • 62,789
  • 6
  • 49
  • 67
0

The fastest approach for this, if you have a LOT of libraries, is to use proc metadata.

The below is an extract from a SASjs core macro (this one: https://github.com/sasjs/core/blob/main/meta/mm_getlibs.sas)

/* get list of libraries */
filename response temp;
proc metadata in=
  '<GetMetadataObjects>
  <Reposid>$METAREPOSITORY</Reposid>
  <Type>SASLibrary</Type>
  <Objects/>
  <NS>SAS</NS>
  <Flags>%eval(2048+256+8)</Flags>
  <Options/>
  </GetMetadataObjects>'
  out=response;
run;

/* create an XML map to read the response */
filename sxlemap temp;
data _null_;
  file sxlemap;
  put '<SXLEMAP version="1.2" name="SASLibrary">';
  put '<TABLE name="SASLibrary">';
  put '<TABLE-PATH syntax="XPath">//Objects/SASLibrary</TABLE-PATH>';
  put '<COLUMN name="LibraryId">><LENGTH>17</LENGTH>';
  put '<PATH syntax="XPath">//Objects/SASLibrary/@Id</PATH></COLUMN>';
  put '<COLUMN name="LibraryName"><LENGTH>256</LENGTH>>';
  put '<PATH syntax="XPath">//Objects/SASLibrary/@Name</PATH></COLUMN>';
  put '<COLUMN name="LibraryRef"><LENGTH>8</LENGTH>';
  put '<PATH syntax="XPath">//Objects/SASLibrary/@Libref</PATH></COLUMN>';
  put '<COLUMN name="Engine">><LENGTH>12</LENGTH>';
  put '<PATH syntax="XPath">//Objects/SASLibrary/@Engine</PATH></COLUMN>';
  put '</TABLE></SXLEMAP>';
run;
libname _XML_ xml xmlfileref=response xmlmap=sxlemap;

/* sort the response by library name */
proc sort data=_XML_.saslibrary out=work.metalibs;
  by libraryname;
run;

To find the ones assigned to a specific app server, as Joe also mentions, you'd need to iterate further with each library id to get the attributes. For that it can help to have a metadata browser. If you don't have Base SAS (which has metabrowse built in) feel free to contact me and I'll send you a tool for that.

Allan Bowe
  • 12,306
  • 19
  • 75
  • 124
0

Joe's answer can be further condensed as

/* Create metadata libraries listing/inventory */
data META_LIBS (drop=i rc ouri);
   length NAME $256 LIBREF $8 ouri $35;
   call missing(of _char_);
   do i=1 by 1 while(metadata_getnobj("omsobj:SASLibrary?@Id contains '.'", i, ouri) > 0);
      rc = metadata_getattr(ouri, 'Name', NAME);
      rc = metadata_getattr(ouri, 'Libref', LIBREF);
      output;
   end;
run;

See its detailed explanation in this section Creating metadata libraries inventory and identifying duplicate LIBREF.