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.
On
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.
On
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.
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 themetadata_getnobjfunction. Something like this:The example from the documentation otherwise should match what you're doing:
You could then iterate through those, with a
do n = 1 by 1 until (n lt 0);loop or similar, and use themetadata_getattrfunction to obtain the information you want about eachuri. 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: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.