Published on :
Administration INTERNAL_CREATION

Extracting Database Library Metadata

This code is also available in: Deutsch Español Français
Awaiting validation
Attention : This code requires administrator privileges.
This program connects to a SAS© metadata server (SAS© 9 technology) to inventory DBMS-type libraries. It uses SAS© metadata interface functions (`metadata_resolve`, `metadata_get...`) to extract configuration information such as library name, application server, schema, database server, source connections, and authentication domains. Although technically executable in SAS© Viya, it depends on the presence of and connection to a legacy SAS© 9 metadata server.
Data Analysis

Type : INTERNAL_CREATION


Data is dynamically generated by querying metadata server objects via system function calls.

1 Code Block
GLOBAL OPTIONS
Explanation :
Definition of metadata server connection parameters (host, port, credentials).
Copied!
1options
2 metaserver="<hostname>"
3 metaport=8561
4 metauser="sasadm @saspw"
5 metapass="<password>"
6 metarepository=Foundation
7 metaprotocol=bridge;
2 Code Block
DATA STEP Data
Explanation :
This Data Step block performs the main extraction. It initializes a search for 'SASLibrary' type objects configured as DBMS. It then iterates over each found library to retrieve its attributes and related objects (Login, Schema, Connection, Domain) via the 'metadata_getnasn' (associations) and 'metadata_getattr' (attributes) functions, then stores the result in the 'work.libinfo' table.
Copied!
1DATA work.libinfo;
2 
3 /*declare and initialize variables */
4 LENGTH
5 type user schema $ 20
6 lib_uri lib_name app_uri app_name schema_uri login_uri dom_uri
7 dbms_uri dbms_name conn_uri prop_uri datasrc authdomain $ 50
8 id $ 17;
9 keep lib_name app_name user schema dbms_name datasrc authdomain;
10 call missing(of _character_);
11 
12 obj="omsobj:SASLibrary? @IsDBMSLibname = '1'";
13 
14 /* Search Metadata for libraries */
15 libcount=metadata_resolve(obj,type,id);
16 put "INFO: Found " libcount "database libraries.";
17 
18 IF libcount > 0 THEN DO n=1 to libcount;
19 rc=metadata_getnobj(obj,n,lib_uri);
20 rc=metadata_getattr(lib_uri,"Name",lib_name);
21 rc=metadata_getnasn(lib_uri,"DefaultLogin",1,login_uri);
22 rc=metadata_getattr(login_uri,"UserID",user);
23 rc=metadata_getnasn(lib_uri,"DeployedComponents",1,app_uri);
24 rc=metadata_getattr(app_uri,"Name",app_name);
25 rc=metadata_getnasn(lib_uri,"UsingPackages",1,schema_uri);
26 rc=metadata_getattr(schema_uri,"SchemaName",schema);
27 rc=metadata_getnasn(schema_uri,"DeployedComponents",1,dbms_uri);
28 rc=metadata_getattr(dbms_uri,"Name",dbms_name);
29 rc=metadata_getnasn(dbms_uri,"SourceConnections",1,conn_uri);
30 rc=metadata_getnasn(conn_uri,"Properties",1,prop_uri);
31 rc=metadata_getattr(prop_uri,"DefaultValue",datasrc);
32 rc=metadata_getnasn(conn_uri,"Domain",1,dom_uri);
33 rc=metadata_getattr(dom_uri,"Name",authdomain);
34 OUTPUT; /* Push results to table */
35 END;
36 ELSE put "INFO: No libraries to resolve.";
37RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Author: Greg Wootton Date: 22DEC2016


Banner
Expert Advice
Expert
Simon
Expert SAS et fondateur.
« Expert Advice: Navigating DBMS Metadata through SAS Open Metadata Architecture
Utilizing METADATA_* interface functions is the gold standard for auditing and documenting a SAS 9 ecosystem. This script effectively "unwinds" the complex web of technical dependencies—tracing the path from a logical SAS library back to its physical database server, schema, and authentication domain. This level of insight is impossible to achieve with standard dictionary tables. »