28%macro mm_createfolder(path=,mDebug=0);
29%put &sysmacroname: execution started
for &path;
31%
if &mDebug=0 %then %let dbg=*;
33%local parentFolderObjId child errorcheck paths;
37%
if &syscc ge 4 %then %
do;
38 %put SYSCC=&syscc -
this macro requires a clean session;
43 length objId parentId objType parent child $200
45 call missing (of _all_);
46 folderPath =
"%trim(&path)";
48 *
remove any trailing slash ;
49 if ( substr(folderPath,length(folderPath),1) =
'/' ) then
50 folderPath=substr(folderPath,1,length(folderPath)-1);
52 * name must not be blank;
53 if ( folderPath =
'' ) then
do;
54 put
'ERR' +(-1)
"OR: &sysmacroname PATH parameter value must be non-blank";
57 * must have a starting slash ;
58 if ( substr(folderPath,1,1) ne
'/' ) then
do;
59 put
'ERR' +(-1)
"OR: &sysmacroname PATH param value must have starting slash";
63 * check
if folder already exists ;
64 rc=metadata_pathobj(
'',cats(folderPath,
"(Folder)"),
"",objType,objId);
66 put
"NOTE: Folder " folderPath
" already exists!";
70 *
do not create a root (one level) folder ;
71 if countc(folderPath,
'/')=1 then
do;
72 put
'ERR' +(-1)
"OR: &sysmacroname will not create a new ROOT folder";
76 * check that root folder exists ;
77 root=cats(
'/',scan(folderpath,1,
'/'),
"(Folder)");
78 if metadata_pathobj(
'',root,
"",objType,parentId)<1 then
do;
79 put
'ERR' +(-1)
"OR: " root
" does not exist!";
83 * check that parent folder exists ;
84 child=scan(folderPath,-1,
'/');
85 parent=substr(folderpath,1,length(folderpath)-length(child)-1);
86 rc=metadata_pathobj(
'',cats(parent,
"(Folder)"),
"",objType,parentId);
88 putlog
'The following folders will be created:';
92 do x=2 to countw(folderpath,
'/');
95 newpath=cats(newpath,
'/',scan(folderpath,i,
'/'));
97 rc=metadata_pathobj(
'',cats(newpath,
"(Folder)"),
"",objType,parentId);
100 call symputx(cats(
'path',paths),newpath);
103 call symputx(
'paths',paths);
106 else putlog
"parent " parent
" exists";
108 call symputx(
'parentFolderObjId',parentId,
'l');
109 call symputx(
'child',child,
'l');
110 call symputx(
'errorcheck',0,
'l');
115%
if &errorcheck=1 or &syscc ge 4 %then %
return;
117%
if &paths>0 %then %
do x=1 %to &paths;
118 %put executing recursive call
for &&path&x;
119 %mm_createfolder(path=&&path&x)
122 filename __newdir temp;
123 options noquotelenmax;
125 %put creating: &path;
126 %let inmeta=<AddMetadata><Reposid>$METAREPOSITORY</Reposid><Metadata>
127 <Tree Name=
'&child' PublicType=
'Folder' TreeType=
'BIP Folder'
128 UsageVersion=
'1000000'><ParentTree><Tree ObjRef=
'&parentFolderObjId'/>
129 </ParentTree></Tree></Metadata><NS>SAS</NS><Flags>268435456</Flags>
132 proc metadata in=
"&inmeta" out=__newdir verbose;
137 length objId parentId objType parent child $200 ;
138 call missing (of _all_);
139 rc=metadata_pathobj(
'',cats(
"&path",
"(Folder)"),
"",objType,objId);
141 putlog
"SUCCCESS! &path created.";
144 putlog
'ERR' +(-1)
"OR: unsuccessful attempt to create &path";
145 call symputx(
'syscc',8);
150 %
if &mDebug ne 0 %then %
do;
152 infile __newdir lrecl=32767;
157 filename __newdir clear;
160%put &sysmacroname: execution finished
for &path;
161%mend mm_createfolder;