Published on :
Général CREATION_INTERNE

Sans titre

This code is also available in: Deutsch Español Français
Awaiting validation
Attention : This code requires administrator privileges.
This macro uses the `PROC METADATA` procedure to send a `<GetTypes>` request to the SAS© metadata server. The XML response is stored in a temporary file. The script then dynamically generates an XML mapping file (XML Map) to extract the ID, Description, and HasSubtypes fields. Finally, the data is converted into a SAS© table via the LIBNAME XML engine and sorted. IMPORTANT NOTE: This code relies on the SAS© 9 metadata server architecture. It is not compatible with the native SAS© Viya 4 architecture (based on microservices) and will only work if executed in a context connected to a legacy SAS© 9 server.
Data Analysis

Type : CREATION_INTERNE


The data comes from a system query of the metadata server (PROC METADATA) and is processed via temporary files generated by the script.

1 Code Block
PROC METADATA
Explanation :
Sends a formatted XML request to the metadata server to retrieve the list of available object types. The response is stored in the temporary fileref 'response'.
Copied!
1filename response temp;
2/* get list of libraries */
3PROC METADATA in=
4 '<GetTypes>
5 <Types/>
6 <NS>SAS</NS>
7 <!-- specify the OMI_SUCCINCT flag -->
8 <Flags>2048</Flags>
9 <Options>
10 <!-- include <REPOSID> XML element and a repository identifier -->
11 <Reposid>$METAREPOSITORY</Reposid>
12 </Options>
13 </GetTypes>'
14 out=response;
15RUN;
2 Code Block
DATA STEP
Explanation :
Writes the raw XML response content to the SAS log for debugging purposes.
Copied!
1DATA _null_;
2 INFILE response lrecl=1048576;
3 INPUT;
4 put _infile_;
5RUN;
3 Code Block
DATA STEP
Explanation :
Dynamically creates an 'XML Map' file (sxlemap) that defines how to parse the XML stream returned by PROC METADATA to extract a tabular structure.
Copied!
1filename sxlemap temp;
2DATA _null_;
3 file sxlemap;
4 put '<SXLEMAP version="1.2" name="SASTypes"><TABLE name="SASTypes">';
5 put '<TABLE-PATH syntax="XPath">//GetTypes/Types/Type</TABLE-PATH>';
6 put '<COLUMN name="ID"><LENGTH>64</LENGTH>';
7 put '<PATH syntax="XPath">//GetTypes/Types/Type/ @Id</PATH></COLUMN>';
8 /* ... (autres colonnes) ... */
9 put '</TABLE></SXLEMAP>';
10RUN;
4 Code Block
PROC SORT Data
Explanation :
Uses the LIBNAME XML engine to read the 'response' file by applying the 'sxlemap' map, then sorts the extracted data by the 'ID' column to create the final output table.
Copied!
1LIBNAME _XML_ xml xmlfileref=response xmlmap=sxlemap;
2/* sort the response by library name */
3PROC SORT DATA=_XML_.sastypes out=&outds;
4 BY id;
5RUN;
5 Code Block
Cleanup
Explanation :
Releases references to temporary files and the XML library.
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.
Banner
Expert Advice
Expert
Michael
Responsable de l'infrastructure Viya.
« This program is inseparable from the Open Metadata Architecture (OMA). In SAS Viya, this "Type" concept is replaced by resource definitions managed by various microservices (Folders, Files, Identities). Consequently, this code cannot be used to explore native Viya infrastructure unless you are working in a hybrid environment where Viya must still interact with a remote legacy 9.4 Metadata Server. »