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!
filename response temp;
/* get list of libraries */
proc metadata in=
"<GetMetadataObjects><Reposid>$METAREPOSITORY</Reposid>
<Type>&type</Type><Objects/><NS>SAS</NS>
<Flags>0</Flags><Options/></GetMetadataObjects>"
out=response;
run;
Explanation : Debugging step writing the raw XML response received from the metadata server to the SAS log.
Copied!
data _null_;
infile response lrecl=1048576;
input;
put _infile_;
run;
1
DATA _null_;
2
INFILE response lrecl=1048576;
3
INPUT;
4
put _infile_;
5
RUN;
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!
filename sxlemap temp;
data _null_;
file sxlemap;
put '<SXLEMAP version="1.2" name="SASObjects"><TABLE name="SASObjects">';
put "<TABLE-PATH syntax='XPath'>/GetMetadataObjects/Objects/&type";
put "</TABLE-PATH>";
/* ... (création du mapping XML) ... */
put '</COLUMN></TABLE></SXLEMAP>';
run;
1
filename sxlemap temp;
2
DATA _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>';
9
RUN;
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!
libname _XML_ xml xmlfileref=response xmlmap=sxlemap;
proc sort data= _XML_.SASObjects out=&outds;
by name;
run;
1
LIBNAME _XML_ xml xmlfileref=response xmlmap=sxlemap;
2
3
PROC SORTDATA= _XML_.SASObjects out=&outds;
4
BY name;
5
RUN;
5 Code Block
Nettoyage
Explanation : Removes references to temporary files and the XML library to leave the environment clean.
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.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.