BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MariaD
Barite | Level 11

Hi folks, 

 

There is any easy way to retrieve all libnames with libid from metadata?

 

Regards, 

1 ACCEPTED SOLUTION

Accepted Solutions
Nigel_Pain
Lapis Lazuli | Level 10

I think this should do it:

options metaserver=<metaservername>
		metauser=<userid>
		metapass=<password>;

data _null_;
length uri libid name libref $256;
n = 1;
nobj=metadata_getnobj("omsobj:saslibrary?@id contains '.'",n,uri);
do while (nobj > 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;

View solution in original post

3 REPLIES 3
Nigel_Pain
Lapis Lazuli | Level 10

I think this should do it:

options metaserver=<metaservername>
		metauser=<userid>
		metapass=<password>;

data _null_;
length uri libid name libref $256;
n = 1;
nobj=metadata_getnobj("omsobj:saslibrary?@id contains '.'",n,uri);
do while (nobj > 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;
alexal
SAS Employee

@MariaD ,

 

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<=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>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<=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>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<=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>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"') > 0; */
run;

Please see more examples here https://go.documentation.sas.com/?docsetId=lrmeta&docsetTarget=p1k9zipe59ha2an1pq34gu143lay.htm&docs...

MariaD
Barite | Level 11

Thanks @alexal  and @Nigel_Pain , works fine!

suga badge.PNGThe SAS Users Group for Administrators (SUGA) is open to all SAS administrators and architects who install, update, manage or maintain a SAS deployment. 

Join SUGA 

Get Started with SAS Information Catalog in SAS Viya

SAS technical trainer Erin Winters shows you how to explore assets, create new data discovery agents, schedule data discovery agents, and much more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1952 views
  • 2 likes
  • 3 in conversation