Example: Data Step View of Libraries Registered in Metadata

Follow

Overview

This example provides data step code that will query the SAS Metadata and return a list of registered Library References.  The code as-is will create a data step view in the work library, so each time it is accessed it will dynamically query the SAS Metadata.

How to use it

The data step code below assumes that the connection to your Metadata Server has already been configured using the following System Options:

  • METASERVER
  • METAPORT
  • METAUSER
  • METAPASS
If you are running this code via an IOM client (e.g. Enterprise Guide, DI Studio, etc.) then these options will already be set to the user you have logged into SAS with.  If you are running this code from Base SAS you will need to issue an OPTIONS statement to set them.
 
Because access to the SAS Metadata requires security authorisation, the list of Libraries returned will be dependent on what the user specified in the METAUSER/METAPASS options can access.
 

Example

List of Libraries in Metadata

 

Code

******************************************************************************
* Purpose: Create a dynamic view of Libraries registered in Metadata
* Notes  : You must establish a Metadata connection prior to running
******************************************************************************;
data work.liblist(drop=_: label="SAS Library List") / view=work.liblist;
  length id $17 _uri _liburi _extensionuri name description libref engine preassigned hidden
    extension_name extension_value _modified _created location _location $256;
  length created modified 8;
  format created modified datetime.;
  label id="Metadata ID"
        name="Library Name"
        description="Description"
        location="Folder Location"
        libref="Library Reference"
        engine="Engine"
        preassigned="Pre-Assigned Flag"
        hidden="Hidden Flag"
        extension_count="Extension Count"
        extension_name="Extension Name"
        extension_value="Extension Value"
        created="Created"
        modified="Last Modified";
  _nobj=1;
  _n=1;
  call missing(id, _uri, _liburi, _extensionuri, name, description, libref, engine, preassigned, hidden, 
       _modified, _created, _location);
 
  do while(_n le _nobj);
    call missing(extension_name, extension_value, extension_count);
    _nobj=metadata_getnobj("omsobj:SASLibrary?@Id contains '.'",_n,_uri);
    _liburi=_uri;
    _rc=metadata_getattr(_uri,"Id",id);
    _rc=metadata_getattr(_uri,"Name",name);
    _rc=metadata_getattr(_uri,"Desc",description);
    _rc=metadata_getattr(_uri,"Libref",libref);
    _rc=metadata_getattr(_uri,"Engine",engine);
    _rc=metadata_getattr(_uri,"IsPreassigned",preassigned);
    _rc=metadata_getattr(_uri,"IsHidden",hidden);
    _rc=metadata_getattr(_uri,"MetadataCreated",_created);
    _rc=metadata_getattr(_uri,"MetadataUpdated",_modified);
 
    created=input(_created,anydtdtm.);
    modified=input(_modified,anydtdtm.);
 
    * Get folder object the current Library is in *;
    _rc=metadata_getnasn(_uri,"Trees",1,_uri);
    * Get folder name the current Library is in *;
    _rc=metadata_getattr(_uri,"Name",location);
    _tree=1;
    * Loop up the folder hierarchy *;
    do while (_tree>0);
      * Get the parent folder object *;
      _tree=metadata_getnasn(_uri,"ParentTree",1,_uri);
      if _tree > 0 then do;
        * If there was a parent folder, get the name *;
        _rc=metadata_getattr(_uri,"Name",_location);
        * Construct the path *;
        location=catx('/',_location,location);
      end;
    end* Folder Hierachy *;
 
    location = '/'||location;
 
    /* Get extensions */
    _extensionrc=1;_extension_count=1;extension_count=0;
    do while(_extensionrc>0);
      _extensionrc=metadata_getnasn(_liburi,
              "Extensions",
              _extension_count,
              _extensionuri);
      _arc=1;
      if (_extensionrc>0then do;
        _arc=metadata_getattr(_extensionuri,"Name",extension_name);
        _arc=metadata_getattr(_extensionuri,"Value",extension_value);
      end;
      if (_arc=0then do;
        extension_count=_extensionrc;
        output;
        _libwithextension=1;
      end;
      _extension_count=_extension_count+1;
    end;
    if _libwithextension=1 then _libwithextension=0;
    else output;
    _n=_n+1;
  end;
run;
 
Sample files and code examples are provided by Scorpio Software Services "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that Scorpio Software Services shall not be liable for any damages whatsoever arising out of their use of this material.
Was this article helpful?
1 out of 1 found this helpful

Comments

Powered by Zendesk