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.
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.
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
.
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.
Joe's answer can be further condensed as
See its detailed explanation in this section Creating metadata libraries inventory and identifying duplicate LIBREF.