Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mm_tree.sas
Go to the documentation of this file.
1/**
2 @file mm_tree.sas
3 @brief Returns all folders / subfolder content for a particular root
4 @details Shows all members and SubTrees for a particular root.
5
6 Model:
7
8 metauri char(64),
9 name char(256) format=$256. informat=$256. label='name',
10 path char(1024),
11 publictype char(32),
12 MetadataUpdated char(32),
13 MetadataCreated char(32)
14
15 Usage:
16
17 %* load macros;
18 filename mc url
19 "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
20 %inc mc;
21
22 %* export everything;
23 %mm_tree(root= ,outds=iwantthisdataset)
24
25 %* export everything in a specific folder;
26 %mm_tree(root=%str(/my/folder) ,outds=stuff)
27
28 %* export only folders;
29 %mm_tree(root=%str(/my/folder) ,types=Folder ,outds=stuf)
30
31 %* show only exportable content;
32 %mm_tree(root=%str(/) ,types=EXPORTABLE ,outds=exportable)
33
34 %* with specific types;
35 %mm_tree(root=%str(/my/folder)
36 ,types=
37 DeployedJob
38 ExternalFile
39 Folder
40 Folder.SecuredData
41 GeneratedTransform
42 InformationMap.Relational
43 Job
44 Library
45 Prompt
46 StoredProcess
47 Table
48 ,outds=morestuff)
49
50 <h4> SAS Macros </h4>
51 @li mf_getquotedstr.sas
52 @li mm_getpublictypes.sas
53 @li mf_isblank.sas
54
55 @param [in] root= the parent folder under which to return all contents
56 @param [in] outds= the dataset to create that contains the list of directories
57 @param [in] types= Space-seperated, unquoted list of types for filtering the
58 output. Special types:
59
60 * ALl - return all types (the default)
61 * EXPORTABLE - return only the content types that can be exported in an SPK
62
63 @version 9.4
64 @author Allan Bowe
65
66**/
67%macro mm_tree(
68 root=
69 ,types=ALL
70 ,outds=work.mm_tree
71)/*/STORE SOURCE*/;
72options noquotelenmax;
73
74%if %mf_isblank(&root) %then %let root=/;
75
76%if %str(&types)=EXPORTABLE %then %do;
77 data;run;%local tempds; %let tempds=&syslast;
78 %mm_getpublictypes(outds=&tempds)
79 proc sql noprint;
80 select publictype into: types separated by ' ' from &tempds;
81 drop table &tempds;
82%end;
83
84* use a temporary fileref to hold the response;
85filename response temp;
86/* get list of libraries */
87proc metadata in=
88 '<GetMetadataObjects><Reposid>$METAREPOSITORY</Reposid>
89 <Type>Tree</Type><Objects/><NS>SAS</NS>
90 <Flags>384</Flags>
91 <XMLSelect search="*[@TreeType=&apos;BIP Folder&apos;]"/>
92 <Options/></GetMetadataObjects>'
93 out=response;
94run;
95/*
96data _null_;
97 infile response;
98 input;
99 put _infile_;
100 run;
101*/
102
103/* create an XML map to read the response */
104filename sxlemap temp;
105data _null_;
106 file sxlemap;
107 put '<SXLEMAP version="1.2" name="SASObjects"><TABLE name="SASObjects">';
108 put "<TABLE-PATH syntax='XPath'>/GetMetadataObjects/Objects/Tree";
109 put "</TABLE-PATH>";
110 put '<COLUMN name="pathuri">';
111 put "<PATH syntax='XPath'>/GetMetadataObjects/Objects/Tree/@Id</PATH>";
112 put "<TYPE>character</TYPE><DATATYPE>string</DATATYPE><LENGTH>64</LENGTH>";
113 put '</COLUMN><COLUMN name="name">';
114 put "<PATH syntax='XPath'>/GetMetadataObjects/Objects/Tree/@Name</PATH>";
115 put "<TYPE>character</TYPE><DATATYPE>string</DATATYPE><LENGTH>256</LENGTH>";
116 put '</COLUMN></TABLE></SXLEMAP>';
117run;
118libname _XML_ xml xmlfileref=response xmlmap=sxlemap;
119
120data &outds;
121 length metauri pathuri $64 name $256 path $1024
122 publictype MetadataUpdated MetadataCreated $32;
123 set _XML_.SASObjects;
124 keep metauri name publictype MetadataUpdated MetadataCreated path;
125 length parenturi pname $128 ;
126 call missing(parenturi,pname);
127 path=cats('/',name);
128 /* get parents */
129 tmpuri=pathuri;
130 do while (metadata_getnasn(tmpuri,"ParentTree",1,parenturi)>0);
131 rc=metadata_getattr(parenturi,"Name",pname);
132 path=cats('/',pname,path);
133 tmpuri=parenturi;
134 end;
135
136 if path=:"&root";
137
138 %if "&types"="ALL" or ("&types" ne "ALL" and "&types" ne "Folder") %then %do;
139 n=1;
140 do while (metadata_getnasn(pathuri,"Members",n,metauri)>0);
141 n+1;
142 call missing(name,publictype,MetadataUpdated,MetadataCreated);
143 rc=metadata_getattr(metauri,"Name", name);
144 rc=metadata_getattr(metauri,"MetadataUpdated", MetadataUpdated);
145 rc=metadata_getattr(metauri,"MetadataCreated", MetadataCreated);
146 rc=metadata_getattr(metauri,"PublicType", PublicType);
147 %if "&types" ne "ALL" %then %do;
148 if publictype in (%mf_getquotedstr(&types)) then output;
149 %end;
150 %else output; ;
151 end;
152 %end;
153
154 rc=metadata_resolve(pathuri,pname,tmpuri);
155 metauri=cats('OMSOBJ:',pname,'\',pathuri);
156 rc=metadata_getattr(metauri,"Name", name);
157 rc=metadata_getattr(pathuri,"MetadataUpdated", MetadataUpdated);
158 rc=metadata_getattr(pathuri,"MetadataCreated", MetadataCreated);
159 rc=metadata_getattr(pathuri,"PublicType", PublicType);
160 path=substr(path,1,length(path)-length(name)-1);
161 if publictype ne '' then output;
162run;
163
164proc sort;
165 by path;
166run;
167
168/* clear references */
169filename sxlemap clear;
170filename response clear;
171libname _XML_ clear;
172
173%mend mm_tree;