<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Retrieve lib names and libid from metadata in Administration and Deployment</title>
    <link>https://communities.sas.com/t5/Administration-and-Deployment/Retrieve-lib-names-and-libid-from-metadata/m-p/676738#M19674</link>
    <description>&lt;P&gt;I think this should do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options metaserver=&amp;lt;metaservername&amp;gt;
		metauser=&amp;lt;userid&amp;gt;
		metapass=&amp;lt;password&amp;gt;;

data _null_;
length uri libid name libref $256;
n = 1;
nobj=metadata_getnobj("omsobj:saslibrary?@id contains '.'",n,uri);
do while (nobj &amp;gt; 0);
	rc = metadata_getattr(uri,"Name",name);
	rc = metadata_getattr(uri,"libref",libref);
	libid=scan(uri,2,"\");
	put libid= name= libref=;
	n + 1;
	nobj=metadata_getnobj("omsobj:saslibrary?@id contains '.'",n,uri);
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 14 Aug 2020 14:14:40 GMT</pubDate>
    <dc:creator>Nigel_Pain</dc:creator>
    <dc:date>2020-08-14T14:14:40Z</dc:date>
    <item>
      <title>Retrieve lib names and libid from metadata</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/Retrieve-lib-names-and-libid-from-metadata/m-p/676727#M19673</link>
      <description>&lt;P&gt;Hi folks,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is any easy way to retrieve all libnames with libid from metadata?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Aug 2020 13:43:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/Retrieve-lib-names-and-libid-from-metadata/m-p/676727#M19673</guid>
      <dc:creator>MariaD</dc:creator>
      <dc:date>2020-08-14T13:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve lib names and libid from metadata</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/Retrieve-lib-names-and-libid-from-metadata/m-p/676738#M19674</link>
      <description>&lt;P&gt;I think this should do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options metaserver=&amp;lt;metaservername&amp;gt;
		metauser=&amp;lt;userid&amp;gt;
		metapass=&amp;lt;password&amp;gt;;

data _null_;
length uri libid name libref $256;
n = 1;
nobj=metadata_getnobj("omsobj:saslibrary?@id contains '.'",n,uri);
do while (nobj &amp;gt; 0);
	rc = metadata_getattr(uri,"Name",name);
	rc = metadata_getattr(uri,"libref",libref);
	libid=scan(uri,2,"\");
	put libid= name= libref=;
	n + 1;
	nobj=metadata_getnobj("omsobj:saslibrary?@id contains '.'",n,uri);
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Aug 2020 14:14:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/Retrieve-lib-names-and-libid-from-metadata/m-p/676738#M19674</guid>
      <dc:creator>Nigel_Pain</dc:creator>
      <dc:date>2020-08-14T14:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve lib names and libid from metadata</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/Retrieve-lib-names-and-libid-from-metadata/m-p/676739#M19675</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/36451"&gt;@MariaD&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.Libraries;

/* The LENGTH statement defines variables for function arguments and
assigns the maximum length for each variable.  */

  length LibId LibName $ 32 LibRef LibEngine $ 8 LibPath $ 256
ServerContext uri uri2 type $ 256 server $ 32;

/* The LABEL statement assigns descriptive labels to variables. */

  label
LibId = "Library Id"
LibName = "Library Name"
LibRef = "SAS Libref"
LibEngine = "Library Engine"
ServerContext = "Server Contexts"
LibPath = "Library Path"
;

/* The CALL MISSING routine initializes output variables to missing values.  */

  call missing(LibId,LibName,LibRef,LibEngine,LibPath,
       ServerContext,uri,uri2,type,server);
  n=1;
  n2=1;

  /* The METADATA_GETNOBJ function gets the first Library object. If none 
are found, the program prints an informational message. */
  rc=metadata_getnobj("omsobj:SASLibrary?@Id contains '.'",n,uri);
  if rc&amp;lt;=0 then put "NOTE: rc=" rc 
    "There are no Libraries defined in this repository"
    " or there was an error reading the repository.";

/* The DO statement specifies a group of statements to be executed as a unit
for the object that is returned by METADATA_GETNOBJ. The METADATA_GETATTR 
function gets the values of the Id, Name, LibRef, and Engine attributes 
of the SASLibrary object.  */

  do while(rc&amp;gt;0);
     objrc=metadata_getattr(uri,"Id",LibId);
     objrc=metadata_getattr(uri,"Name",LibName);
objrc=metadata_getattr(uri,"Libref",LibRef);
objrc=metadata_getattr(uri,"Engine",LibEngine);

	 /* The METADATA_GETNASN function gets objects associated 
via the DeployedComponents association. If none are found, the program
prints an informational message. */

	 objrc=metadata_getnasn(uri,"DeployedComponents",n2,uri2);
	 if objrc&amp;lt;=0 then
       do;
         put "NOTE: There is no DeployedComponents association for "
             LibName +(-1)", and therefore no server context.";
	     ServerContext="";
	   end;

 /* When an association is found, the METADATA_GETATTR function gets
the server name. */
 
	   do while(objrc&amp;gt;0);
         objrc=metadata_getattr(uri2,"Name",server);
	     if n2=1 then ServerContext=quote(trim(server));
		 else ServerContext=trim(ServerContext)||" "||quote(trim(server));

/* Look for another ServerContext */
	     n2+1;
         objrc=metadata_getnasn(uri,"DeployedComponents",n2,uri2);
	   end; /*do while objrc*/ 

     n2=1;

	 /* The METADATA_GETNASN function gets objects associated via the 
UsingPackages association. The program prints a message if an 
association is not found.*/

	 objrc=metadata_getnasn(uri,"UsingPackages",n2,uri2);
	 if objrc&amp;lt;=0 then
       do;
         put "NOTE: There is no UsingPackages association for " 
             LibName +(-1)", and therefore no Path.";
	     LibPath="";
	   end;

/* When a UsingPackages association is found, the METADATA_RESOLVE function 
is called to resolve the URI to an object on the metadata server. */

	   do while(objrc&amp;gt;0);
	     objrc=metadata_resolve(uri2,type,id);

	/*if type='Directory', the METADATA_GETATTR function is used to get its path */

	if type='Directory' then objrc=metadata_getattr(uri2,"DirectoryName",LibPath);

	/*if type='DatabaseSchema', the METADATA_GETATTR function is used to get 
the name */

	 else if type='DatabaseSchema' then objrc=metadata_getattr(uri2, "Name", LibPath);
		 else LibPath="*unknown*";

		/* output the records */
	     output;
	     LibPath="";

		/* Look for other directories or database schemas */

         n2+1;
	     objrc=metadata_getnasn(uri,"UsingPackages",n2,uri2);
	   end; /*do while objrc*/ 

     ServerContext="";
     n+1;

		/* Look for other libraries */

	 n2=1;
     rc=metadata_getnobj("omsobj:SASLibrary?@Id contains '.'",n,uri);

  end; /*do while rc*/  

/* The KEEP statement defines the variables to include in the output data set. */

  keep
LibId
LibName
LibRef
LibEngine
ServerContext
LibPath; 
run;

/* Write a basic listing of data */

proc print data=work.Libraries label;
  /* subset results if you wish
     where indexw(ServerContext,'"SASMain"') &amp;gt; 0; */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please see more examples here&amp;nbsp;&lt;A href="https://go.documentation.sas.com/?docsetId=lrmeta&amp;amp;docsetTarget=p1k9zipe59ha2an1pq34gu143lay.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n1s6cop3vobpnjn1lz92vu5qpvbw"&gt;https://go.documentation.sas.com/?docsetId=lrmeta&amp;amp;docsetTarget=p1k9zipe59ha2an1pq34gu143lay.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#n1s6cop3vobpnjn1lz92vu5qpvbw&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Aug 2020 14:16:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/Retrieve-lib-names-and-libid-from-metadata/m-p/676739#M19675</guid>
      <dc:creator>alexal</dc:creator>
      <dc:date>2020-08-14T14:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: Retrieve lib names and libid from metadata</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/Retrieve-lib-names-and-libid-from-metadata/m-p/676747#M19676</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/41748"&gt;@alexal&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13516"&gt;@Nigel_Pain&lt;/a&gt;&amp;nbsp;, works fine!&lt;/P&gt;</description>
      <pubDate>Fri, 14 Aug 2020 14:45:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/Retrieve-lib-names-and-libid-from-metadata/m-p/676747#M19676</guid>
      <dc:creator>MariaD</dc:creator>
      <dc:date>2020-08-14T14:45:36Z</dc:date>
    </item>
  </channel>
</rss>

