Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mm_gettree.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Returns the metadata path and object from either the path or object
4 @details Provide a metadata BIP tree path, or the uri for the bottom level
5 folder, to obtain a dataset (<code>&outds</code>) containing both the path
6 and uri.
7
8 Usage:
9
10 %mm_getTree(tree=/User Folders/sasdemo)
11
12
13 @param tree= the BIP Tree folder path or uri
14 @param outds= the dataset to create that contains the tree path & uri
15 @param inds= an optional input dataset to augment with treepath & treeuri
16 @param mDebug= set to 1 to show debug messages in the log
17
18 @returns outds dataset containing the following columns:
19 - treeuri
20 - treepath
21
22 @version 9.2
23 @author Allan Bowe
24
25**/
26
27%macro mm_getTree(
28 tree=
29 ,inds=
30 ,outds=work.mm_getTree
31 ,mDebug=0
32)/*/STORE SOURCE*/;
33
34%local mD;
35%if &mDebug=1 %then %let mD=;
36%else %let mD=%str(*);
37%&mD.put Executing mm_getTree.sas;
38%&mD.put _local_;
39
40data &outds;
41 length treeuri __parenturi __type __name $256 treepath $512;
42%if %length(&inds)>0 %then %do;
43 set &inds;
44%end;
45 __rc1=metadata_resolve("&tree",__type,treeuri);
46
47 if __type='Tree' then do;
48 __rc2=metadata_getattr(treeuri,"Name",__name);
49 treepath=cats('/',__name);
50 /* get parents */
51 do while (metadata_getnasn(treeuri,"ParentTree",1,__parenturi)>0);
52 __rc3=metadata_getattr(__parenturi,"Name",__name);
53 treepath=cats('/',__name,treepath);
54 treeuri=__parenturi;
55 end;
56 treeuri="&tree";
57 end;
58 else do;
59 __rc2=metadata_pathobj(' ',"&tree",'Folder',__type,treeuri);
60 treepath="&tree";
61 end;
62
63 &mD.put (_all_)(=);
64 drop __:;
65 if treeuri ne "" and treepath ne "" then output;
66 stop;
67run;
68%mend mm_getTree;