Published on :
Macro CREATION_INTERNE

Retrieve Metadata Objects (mm_getobjects)

This code is also available in: Deutsch Español Français
Awaiting validation
This `mm_getobjects` macro executes an XML request via `PROC METADATA` to extract objects (by default `SASLibrary`) from the metadata repository. It dynamically generates an XML map (SXLEMAP) to parse the XML response and converts 'Id' and 'Name' attributes into a sorted SAS© table. This code is typical for interactions with the SAS© 9 metadata server and might not return results in a pure Viya environment without a bridge to SAS© 9.
Data Analysis

Type : CREATION_INTERNE


Data originates from a system query (PROC METADATA) and is transformed via temporary files and the XML engine.

1 Code Block
PROC METADATA
Explanation :
Sends a formatted XML request (`GetMetadataObjects`) to the metadata server to retrieve objects of the type specified by the macro variable `&type`.
Copied!
1filename response temp;
2/* get list of libraries */
3PROC METADATA in=
4 "<GetMetadataObjects><Reposid>$METAREPOSITORY</Reposid>
5 <Type>&type</Type><Objects/><NS>SAS</NS>
6 <Flags>0</Flags><Options/></GetMetadataObjects>"
7 out=response;
8RUN;
2 Code Block
DATA STEP
Explanation :
Debugging step writing the raw XML response received from the metadata server to the SAS log.
Copied!
1DATA _null_;
2 INFILE response lrecl=1048576;
3 INPUT;
4 put _infile_;
5RUN;
3 Code Block
DATA STEP
Explanation :
Dynamically generates an SXLEMAP file (XML Map) to instruct the SAS XML engine on how to read the hierarchical response and flatten it into 'id' and 'name' columns.
Copied!
1filename sxlemap temp;
2DATA _null_;
3 file sxlemap;
4 put '<SXLEMAP version="1.2" name="SASObjects"><TABLE name="SASObjects">';
5 put "<TABLE-PATH syntax='XPath'>/GetMetadataObjects/Objects/&type";
6 put "</TABLE-PATH>";
7 /* ... (création du mapping XML) ... */
8 put '</COLUMN></TABLE></SXLEMAP>';
9RUN;
4 Code Block
PROC SORT Data
Explanation :
Uses the `LIBNAME XML` engine with the generated map to read the temporary file as a SAS table, sorts the data by name, and saves it to the output table specified by `&outds`.
Copied!
1LIBNAME _XML_ xml xmlfileref=response xmlmap=sxlemap;
2 
3PROC SORT DATA= _XML_.SASObjects out=&outds;
4 BY name;
5RUN;
5 Code Block
Nettoyage
Explanation :
Removes references to temporary files and the XML library to leave the environment clean.
Copied!
1filename sxlemap clear;
2filename response clear;
3LIBNAME _XML_ clear;
4 
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 : Allan Bowe