Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mm_getlibs.sas
Go to the documentation of this file.
1 /**
2  @file
3  @brief Creates a dataset with all metadata libraries
4  @details Will only show the libraries to which a user has the requisite
5  metadata access.
6 
7  @param outds the dataset to create that contains the list of libraries
8  @param mDebug set to anything but * or 0 to show debug messages in the log
9 
10  @returns outds dataset containing all groups in a column named "metagroup"
11  (defaults to work.mm_getlibs). The following columns are provided:
12  - LibraryId
13  - LibraryName
14  - LibraryRef
15  - Engine
16 
17  @warning The following filenames are created and then de-assigned:
18 
19  filename sxlemap clear;
20  filename response clear;
21  libname _XML_ clear;
22 
23  @version 9.2
24  @author Allan Bowe
25 
26 **/
27 
28 %macro mm_getlibs(
29  outds=work.mm_getLibs
30 )/*/STORE SOURCE*/;
31 
32 /*
33  flags:
34 
35  OMI_SUCCINCT (2048) Do not return attributes with null values.
36  OMI_GET_METADATA (256) Executes a GetMetadata call for each object that
37  is returned by the GetMetadataObjects method.
38  OMI_ALL_SIMPLE (8) Gets all of the attributes of the requested object.
39 */
40 data _null_;
41  flags=2048+256+8;
42  call symputx('flags',flags,'l');
43 run;
44 
45 * use a temporary fileref to hold the response;
46 filename response temp;
47 /* get list of libraries */
48 proc metadata in=
49  '<GetMetadataObjects>
50  <Reposid>$METAREPOSITORY</Reposid>
51  <Type>SASLibrary</Type>
52  <Objects/>
53  <NS>SAS</NS>
54  <Flags>&flags</Flags>
55  <Options/>
56  </GetMetadataObjects>'
57  out=response;
58 run;
59 
60 /* write the response to the log for debugging */
61 data _null_;
62  infile response lrecl=32767;
63  input;
64  put _infile_;
65 run;
66 
67 /* create an XML map to read the response */
68 filename sxlemap temp;
69 data _null_;
70  file sxlemap;
71  put '<SXLEMAP version="1.2" name="SASLibrary">';
72  put '<TABLE name="SASLibrary">';
73  put '<TABLE-PATH syntax="XPath">//Objects/SASLibrary</TABLE-PATH>';
74  put '<COLUMN name="LibraryId">><LENGTH>17</LENGTH>';
75  put '<PATH syntax="XPath">//Objects/SASLibrary/@Id</PATH></COLUMN>';
76  put '<COLUMN name="LibraryName"><LENGTH>256</LENGTH>>';
77  put '<PATH syntax="XPath">//Objects/SASLibrary/@Name</PATH></COLUMN>';
78  put '<COLUMN name="LibraryRef"><LENGTH>8</LENGTH>';
79  put '<PATH syntax="XPath">//Objects/SASLibrary/@Libref</PATH></COLUMN>';
80  put '<COLUMN name="Engine">><LENGTH>12</LENGTH>';
81  put '<PATH syntax="XPath">//Objects/SASLibrary/@Engine</PATH></COLUMN>';
82  put '</TABLE></SXLEMAP>';
83 run;
84 libname _XML_ xml xmlfileref=response xmlmap=sxlemap;
85 
86 /* sort the response by library name */
87 proc sort data=_XML_.saslibrary out=&outds;
88  by libraryname;
89 run;
90 
91 
92 /* clear references */
93 filename sxlemap clear;
94 filename response clear;
95 libname _XML_ clear;
96 
97 %mend;