27 %macro mm_createfolder(path=,mDebug=0);
28 %put &sysmacroname: execution started
for &path;
29 %local dbg errorcheck;
30 %
if &mDebug=0 %then %let dbg=*;
32 %local parentFolderObjId child errorcheck paths;
36 %
if &syscc ge 4 %then %
do;
37 %put SYSCC=&syscc -
this macro requires a clean session;
42 length objId parentId objType parent child $200
44 call missing (of _all_);
45 folderPath =
"%trim(&path)";
47 *
remove any trailing slash ;
48 if ( substr(folderPath,length(folderPath),1) =
'/' ) then
49 folderPath=substr(folderPath,1,length(folderPath)-1);
51 * name must not be blank;
52 if ( folderPath =
'' ) then
do;
53 put
"%str(ERR)OR: &sysmacroname PATH parameter value must be non-blank";
56 * must have a starting slash ;
57 if ( substr(folderPath,1,1) ne
'/' ) then
do;
58 put
"%str(ERR)OR: &sysmacroname PATH parameter value must have starting slash";
62 * check
if folder already exists ;
63 rc=metadata_pathobj(
'',cats(folderPath,
"(Folder)"),
"",objType,objId);
65 put
"NOTE: Folder " folderPath
" already exists!";
69 *
do not create a root (one level) folder ;
70 if countc(folderPath,
'/')=1 then
do;
71 put
"%str(ERR)OR: &sysmacroname will not create a new ROOT folder";
75 * check that root folder exists ;
76 root=cats(
'/',scan(folderpath,1,
'/'),
"(Folder)");
77 if metadata_pathobj(
'',root,
"",objType,parentId)<1 then
do;
78 put
"%str(ERR)OR: " root
" does not exist!";
82 * check that parent folder exists ;
83 child=scan(folderPath,-1,
'/');
84 parent=substr(folderpath,1,length(folderpath)-length(child)-1);
85 rc=metadata_pathobj(
'',cats(parent,
"(Folder)"),
"",objType,parentId);
87 putlog
'The following folders will be created:';
91 do x=2 to countw(folderpath,
'/');
94 newpath=cats(newpath,
'/',scan(folderpath,i,
'/'));
96 rc=metadata_pathobj(
'',cats(newpath,
"(Folder)"),
"",objType,parentId);
99 call symputx(cats(
'path',paths),newpath);
102 call symputx(
'paths',paths);
105 else putlog
"parent " parent
" exists";
107 call symputx(
'parentFolderObjId',parentId,
'l');
108 call symputx(
'child',child,
'l');
109 call symputx(
'errorcheck',0,
'l');
114 %
if &errorcheck=1 or &syscc ge 4 %then %
return;
116 %
if &paths>0 %then %
do x=1 %to &paths;
117 %put executing recursive call
for &&path&x;
118 %mm_createfolder(path=&&path&x)
121 filename __newdir temp;
122 options noquotelenmax;
124 %put creating: &path;
125 %let inmeta=<AddMetadata><Reposid>$METAREPOSITORY</Reposid><Metadata>
126 <Tree Name=
'&child' PublicType=
'Folder' TreeType=
'BIP Folder' UsageVersion=
'1000000'>
127 <ParentTree><Tree ObjRef=
'&parentFolderObjId'/></ParentTree></Tree></Metadata>
128 <NS>SAS</NS><Flags>268435456</Flags></AddMetadata>;
130 proc metadata in=
"&inmeta" out=__newdir verbose;
135 length objId parentId objType parent child $200 ;
136 call missing (of _all_);
137 rc=metadata_pathobj(
'',cats(
"&path",
"(Folder)"),
"",objType,objId);
139 putlog
"SUCCCESS! &path created.";
142 putlog
"%str(ERR)OR: unsuccessful attempt to create &path";
143 call symputx(
'syscc',8);
148 %
if &mDebug ne 0 %then %
do;
150 infile __newdir lrecl=32767;
155 filename __newdir clear;
158 %put &sysmacroname: execution finished
for &path;