58 %macro mm_createlibrary(
59 libname=My New Library
61 ,libdesc=Created automatically
using the mm_createlibrary macro
63 ,tree=/User Folders/sasdemo
65 ,directory=/tmp/somelib
73 %
if &mDebug=1 %then %let mD=;
74 %
else %let mD=%str(*);
75 %&mD.put Executing &sysmacroname..sas;
78 %let libref=%upcase(&libref);
85 rc=metadata_resolve(
"omsobj:SASLibrary?@Name='&libname'",type,uri);
86 call symputx(
'checktype',type,
'l');
87 call symputx(
'liburi',uri,
'l');
90 %
if &checktype = SASLibrary %then %
do;
91 %put WARNING: Library (&liburi) already exists with libname (&libname) ;
100 rc=metadata_resolve(
"omsobj:SASLibrary?@Libref='&libref'",type,uri);
101 call symputx(
'checktype',type,
'l');
102 call symputx(
'liburi',uri,
'l');
105 %
if &checktype = SASLibrary %then %
do;
106 %put WARNING: Library (&liburi) already exists with libref (&libref) ;
114 %mm_createfolder(path=&tree)
120 length type uri $256;
121 rc=metadata_pathobj(
"",
"&tree",
"Folder",type,uri);
122 call symputx(
'foldertype',type,
'l');
123 call symputx(
'treeuri',uri,
'l');
125 %
if &foldertype ne Tree %then %
do;
126 %put WARNING: Tree &tree does not exist!;
133 filename &frefin temp;
134 filename &frefout temp;
136 %
if &engine=BASE %then %
do;
138 %mf_verifymacvars(libname libref engine servercontext tree)
146 length type uri $256;
147 rc=metadata_resolve(
"omsobj:ServerContext?@Name='&ServerContext'",type,uri);
148 call symputx(
'checktype',type,
'l');
149 call symputx(
'serveruri',uri,
'l');
152 %
if &checktype ne ServerContext %then %
do;
153 %put %str(ERR)OR: ServerContext (&ServerContext) does not exist!;
161 length type uri str $256;
162 str=
"omsobj:Prototype?@Name='Library.SAS.Prototype.Name.xmlKey.txt'";
163 rc=metadata_resolve(str,type,uri);
164 call symputx(
'checktype',type,
'l');
165 call symputx(
'prototypeuri',uri,
'l');
168 %
if &checktype ne Prototype %then %
do;
169 %put %str(ERR)OR: Prototype (Library.SAS.Prototype.Name.xmlKey.txt) not found!;
176 %if %sysfunc(fileexist(&directory))=0 %then %do;
177 %put %str(ERR)OR: Physical directory (&directory) does not appear to exist!;
185 length type uri $256;
186 rc=metadata_resolve("omsobj:Directory?@DirectoryRole='LibraryPath'"
187 !!" and @DirectoryName='&directory'",type,uri);
188 call symputx('checktype',type,'l');
189 call symputx('directoryuri',uri,'l');
192 %if &checktype ne Directory %then %do;
193 %put NOTE: Directory
object does not exist for (&directory) location;
194 %put NOTE: It will now be created;
198 directory=quote(symget('directory'));
199 put "<AddMetadata><Reposid>$METAREPOSITORY</Reposid><Metadata> "/
200 '<Directory UsageVersion="1000000" IsHidden="0" IsRelative="0"'/
201 ' DirectoryRole="LibraryPath" Name="Path" DirectoryName=' directory '/>'/
202 "</Metadata><NS>SAS</NS>"/
203 "<Flags>268435456</Flags></AddMetadata>";
206 proc metadata in= &frefin out=&frefout %if &mdebug=1 %then verbose;;
208 %if &mdebug=1 %then %do;
210 infile &frefout lrecl=1048576;
214 %put NOTE: Checking to ensure directory (&directory)
object was created;
216 length type uri $256;
217 rc=metadata_resolve("omsobj:Directory?@DirectoryRole='LibraryPath'"
218 !!" and @DirectoryName='&directory'",type,uri);
219 call symputx('checktype2',type,'l');
220 call symputx('directoryuri',uri,'l');
221 %if &mdebug=1 %then putlog (_all_)(=);;
223 %if &checktype2 ne Directory %then %do;
224 %put %str(ERR)OR: Directory (&directory)
object was NOT created!;
227 %else %put NOTE: Directory (&directoryuri) successfully created!;
233 %if %sysevalf(&sysver lt 9.3) %then %do;
234 %put WARNING: Version 9.3 or later required;
243 treeuri=quote(symget('treeuri'));
244 serveruri=quote(symget('serveruri'));
245 directoryuri=quote(symget('directoryuri'));
246 libname=quote(symget('libname'));
247 libref=quote(symget('libref'));
248 IsPreassigned=quote(symget('IsPreassigned'));
249 prototypeuri=quote(symget('prototypeuri'));
252 libdesc=tranwrd(symget('libdesc'),'&','&');
253 libdesc=tranwrd(libdesc,'<','<');
254 libdesc=tranwrd(libdesc,'>','>');
255 libdesc=tranwrd(libdesc,"'",''');
256 libdesc=tranwrd(libdesc,'"','"');
257 libdesc=tranwrd(libdesc,'0A'x,'&
#10;'); 258 libdesc=tranwrd(libdesc,
'0D'x,
' ');
259 libdesc=tranwrd(libdesc,
'$',
'$');
260 libdesc=quote(trim(libdesc));
262 put
"<AddMetadata><Reposid>$METAREPOSITORY</Reposid><Metadata> "/
263 '<SASLibrary Desc=' libdesc
' Engine="BASE" IsDBMSLibname="0" '/
264 ' IsHidden="0" IsPreassigned=' IsPreassigned
' Libref=' libref /
265 ' UsageVersion="1000000" PublicType="Library" name=' libname
'>'/
266 ' <DeployedComponents>'/
267 ' <ServerContext ObjRef=' serveruri
"/>"/
268 ' </DeployedComponents>'/
270 ' <PropertySet Name="ModifiedByProductPropertySet" '/
271 ' SetRole="ModifiedByProductPropertySet" UsageVersion="0" />'/
273 " <Trees><Tree ObjRef=" treeuri
"/></Trees>"/
275 ' <Directory ObjRef=' directoryuri
' />'/
278 ' <Prototype ObjRef=' prototypeuri
'/>'/
279 ' </UsingPrototype>'/
280 '</SASLibrary></Metadata><NS>SAS</NS>'/
281 '<Flags>268435456</Flags></AddMetadata>';
285 proc metadata in= &frefin out=&frefout %
if &mdebug=1 %then verbose ;;
288 %
if &mdebug=1 %then %
do;
290 infile &frefout lrecl=1048576;
294 %put NOTE: Checking to ensure library (&libname) was created;
296 length type uri $256;
297 rc=metadata_pathobj(
"",
"&tree/&libname",
"Library",type,uri);
298 call symputx(
'libtype',type,
'l');
299 call symputx(
'liburi',uri,
'l');
300 %
if &mdebug=1 %then putlog (_all_)(=);;
302 %
if &libtype ne SASLibrary %then %
do;
303 %put %str(ERR)OR: Could not find (&libname) at (&tree)!!;
306 %
else %put NOTE: Library (&libname) successfully created in (&tree)!;
309 %put %str(ERR)OR: Other library engine types are not yet supported!!;
316 %
if &mdebug ne 1 %then %
do;
317 filename &frefin clear;
318 filename &frefout clear;