29%macro mm_createfolder(path=,mDebug=0);
30%put &sysmacroname: execution started
for &path;
32%
if &mDebug=0 %then %let dbg=*;
34%local parentFolderObjId child errorcheck paths;
38%
if &syscc ge 4 %then %
do;
39 %put SYSCC=&syscc -
this macro requires a clean session;
44 length objId parentId objType parent child $200
46 call missing (of _all_);
47 folderPath =
"%trim(&path)";
50 if ( substr(folderPath,length(folderPath),1) =
'/' ) then
51 folderPath=substr(folderPath,1,length(folderPath)-1);
54 if ( folderPath =
'' ) then
do;
55 put
'ERR' +(-1)
"OR: &sysmacroname PATH parameter value must be non-blank";
59 if ( substr(folderPath,1,1) ne
'/' ) then
do;
60 put
'ERR' +(-1)
"OR: &sysmacroname PATH param value must have starting slash";
65 rc=metadata_pathobj(
'',cats(folderPath,
"(Folder)"),
"",objType,objId);
67 put
"NOTE: Folder " folderPath
" already exists!";
72 if countc(folderPath,
'/')=1 then
do;
73 put
'ERR' +(-1)
"OR: &sysmacroname will not create a new ROOT folder";
78 root=cats(
'/',scan(folderpath,1,
'/'),
"(Folder)");
79 if metadata_pathobj(
'',root,
"",objType,parentId)<1 then
do;
80 put
'ERR' +(-1)
"OR: " root
" does not exist!";
85 child=scan(folderPath,-1,
'/');
86 parent=substr(folderpath,1,length(folderpath)-length(child)-1);
87 rc=metadata_pathobj(
'',cats(parent,
"(Folder)"),
"",objType,parentId);
89 putlog
'The following folders will be created:';
93 do x=2 to countw(folderpath,
'/');
96 newpath=cats(newpath,
'/',scan(folderpath,i,
'/'));
98 rc=metadata_pathobj(
'',cats(newpath,
"(Folder)"),
"",objType,parentId);
101 call symputx(cats(
'path',paths),newpath);
104 call symputx(
'paths',paths);
107 else putlog
"parent " parent
" exists";
109 call symputx(
'parentFolderObjId',parentId,
'l');
110 call symputx(
'child',child,
'l');
111 call symputx(
'errorcheck',0,
'l');
116%
if &errorcheck=1 or &syscc ge 4 %then %
return;
118%
if &paths>0 %then %
do x=1 %to &paths;
119 %put executing recursive call
for &&path&x;
120 %mm_createfolder(path=&&path&x)
123 filename __newdir temp;
124 options noquotelenmax;
126 %put creating: &path;
127 %let inmeta=<AddMetadata><Reposid>$METAREPOSITORY</Reposid><Metadata>
128 <Tree Name=
'&child' PublicType=
'Folder' TreeType=
'BIP Folder'
129 UsageVersion=
'1000000'><ParentTree><Tree ObjRef=
'&parentFolderObjId'/>
130 </ParentTree></Tree></Metadata><NS>SAS</NS><Flags>268435456</Flags>
133 proc metadata in=
"&inmeta" out=__newdir verbose;
138 length objId parentId objType parent child $200 ;
139 call missing (of _all_);
140 rc=metadata_pathobj(
'',cats(
"&path",
"(Folder)"),
"",objType,objId);
142 putlog
"SUCCCESS! &path created.";
145 putlog
'ERR' +(-1)
"OR: unsuccessful attempt to create &path";
146 call symputx(
'syscc',8);
151 %
if &mDebug ne 0 %then %
do;
153 infile __newdir lrecl=32767;
158 filename __newdir clear;
161%put &sysmacroname: execution finished
for &path;
162%mend mm_createfolder;