Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mm_getobjects.sas
Go to the documentation of this file.
1 /**
2  @file
3  @brief Creates a dataset with all metadata objects for a particular type
4 
5  @param type= the metadata type for which to return all objects
6  @param outds= the dataset to create that contains the list of types
7 
8  @returns outds dataset containing all objects
9 
10  @warning The following filenames are created and then de-assigned:
11 
12  filename sxlemap clear;
13  filename response clear;
14  libname _XML_ clear;
15 
16  @version 9.2
17  @author Allan Bowe
18 
19 **/
20 
21 %macro mm_getobjects(
22  type=SASLibrary
23  ,outds=work.mm_getobjects
24 )/*/STORE SOURCE*/;
25 
26 
27 * use a temporary fileref to hold the response;
28 filename response temp;
29 /* get list of libraries */
30 proc metadata in=
31  "<GetMetadataObjects><Reposid>$METAREPOSITORY</Reposid>
32  <Type>&type</Type><Objects/><NS>SAS</NS>
33  <Flags>0</Flags><Options/></GetMetadataObjects>"
34  out=response;
35 run;
36 
37 /* write the response to the log for debugging */
38 data _null_;
39  infile response lrecl=1048576;
40  input;
41  put _infile_;
42 run;
43 
44 /* create an XML map to read the response */
45 filename sxlemap temp;
46 data _null_;
47  file sxlemap;
48  put '<SXLEMAP version="1.2" name="SASObjects"><TABLE name="SASObjects">';
49  put "<TABLE-PATH syntax='XPath'>/GetMetadataObjects/Objects/&type</TABLE-PATH>";
50  put '<COLUMN name="id">';
51  put "<PATH syntax='XPath'>/GetMetadataObjects/Objects/&type/@Id</PATH>";
52  put "<TYPE>character</TYPE><DATATYPE>string</DATATYPE><LENGTH>200</LENGTH>";
53  put '</COLUMN><COLUMN name="name">';
54  put "<PATH syntax='XPath'>/GetMetadataObjects/Objects/&type/@Name</PATH>";
55  put "<TYPE>character</TYPE><DATATYPE>string</DATATYPE><LENGTH>200</LENGTH>";
56  put '</COLUMN></TABLE></SXLEMAP>';
57 run;
58 libname _XML_ xml xmlfileref=response xmlmap=sxlemap;
59 
60 proc sort data= _XML_.SASObjects out=&outds;
61  by name;
62 run;
63 
64 /* clear references */
65 filename sxlemap clear;
66 filename response clear;
67 libname _XML_ clear;
68 
69 %mend;