62%macro mm_createlibrary(
63 libname=My New Library
65 ,libdesc=Created automatically using the mm_createlibrary macro
67 ,tree=/User Folders/sasdemo
69 ,directory=/tmp/somelib
77%
if &mDebug=1 %then %let mD=;
79%&mD.put Executing &sysmacroname..sas;
82%let libref=%upcase(&libref);
89 rc=metadata_resolve(
"omsobj:SASLibrary?@Name='&libname'",type,uri);
90 call symputx(
'checktype',type,
'l');
91 call symputx(
'liburi',uri,
'l');
94%
if &checktype = SASLibrary %then %
do;
95 %put %str(WARN)ING: Library (&liburi) already exists with libname (&libname);
103 length type uri $256;
104 rc=metadata_resolve(
"omsobj:SASLibrary?@Libref='&libref'",type,uri);
105 call symputx(
'checktype',type,
'l');
106 call symputx(
'liburi',uri,
'l');
109%
if &checktype = SASLibrary %then %
do;
110 %put %str(WARN)ING: Library (&liburi) already exists with libref (&libref) ;
118%mm_createfolder(path=&tree)
124 length type uri $256;
125 rc=metadata_pathobj(
"",
"&tree",
"Folder",type,uri);
126 call symputx(
'foldertype',type,
'l');
127 call symputx(
'treeuri',uri,
'l');
129%
if &foldertype ne Tree %then %
do;
130 %put %str(WARN)ING: Tree &tree does not exist!;
137filename &frefin temp;
138filename &frefout temp;
141 &engine=BASE & %mf_verifymacvars(libname libref engine servercontext tree)=0
144 ,msg=%str(Empty inputs: libname libref engine servercontext tree)
147%
if &engine=BASE %then %
do;
152 length type uri $256;
153 rc=metadata_resolve(
"omsobj:ServerContext?@Name='&ServerContext'",type,uri);
154 call symputx(
'checktype',type,
'l');
155 call symputx(
'serveruri',uri,
'l');
158 %
if &checktype ne ServerContext %then %
do;
159 %put %str(ERR)OR: ServerContext (&ServerContext) does not exist!;
167 length type uri str $256;
168 str=
"omsobj:Prototype?@Name='Library.SAS.Prototype.Name.xmlKey.txt'";
169 rc=metadata_resolve(str,type,uri);
170 call symputx(
'checktype',type,
'l');
171 call symputx(
'prototypeuri',uri,
'l');
174 %
if &checktype ne Prototype %then %
do;
175 %put %str(ERR)OR: Prototype Library.SAS.Prototype.Name.xmlKey.txt not found;
182 %
if %sysfunc(fileexist(&directory))=0 %then %
do;
183 %put %str(ERR)OR: Physical directory (&directory) does not appear to exist!;
191 length type uri $256;
192 rc=metadata_resolve(
"omsobj:Directory?@DirectoryRole='LibraryPath'"
193 !!
" and @DirectoryName='&directory'",type,uri);
194 call symputx(
'checktype',type,
'l');
195 call symputx(
'directoryuri',uri,
'l');
198 %
if &checktype ne Directory %then %
do;
199 %put NOTE: Directory
object does not exist
for (&directory) location;
200 %put NOTE: It will now be created;
204 directory=quote(symget(
'directory'));
205 put
"<AddMetadata><Reposid>$METAREPOSITORY</Reposid><Metadata> "/
206 '<Directory UsageVersion="1000000" IsHidden="0" IsRelative="0"'/
207 ' DirectoryRole="LibraryPath" Name="Path" DirectoryName=' directory
'/>'/
208 "</Metadata><NS>SAS</NS>"/
209 "<Flags>268435456</Flags></AddMetadata>";
212 proc metadata in= &frefin out=&frefout %
if &mdebug=1 %then verbose;;
214 %
if &mdebug=1 %then %
do;
216 infile &frefout lrecl=1048576;
220 %put NOTE: Checking to ensure directory (&directory)
object was created;
222 length type uri $256;
223 rc=metadata_resolve(
"omsobj:Directory?@DirectoryRole='LibraryPath'"
224 !!
" and @DirectoryName='&directory'",type,uri);
225 call symputx(
'checktype2',type,
'l');
226 call symputx(
'directoryuri',uri,
'l');
227 %
if &mdebug=1 %then putlog (_all_)(=);;
229 %
if &checktype2 ne Directory %then %
do;
230 %put %str(ERR)OR: Directory (&directory)
object was NOT created!;
233 %
else %put NOTE: Directory (&directoryuri) successfully created!;
239 %
if %sysevalf(&sysver lt 9.3) %then %
do;
240 %put %str(WARN)ING: Version 9.3 or later required;
249 treeuri=quote(symget(
'treeuri'));
250 serveruri=quote(symget(
'serveruri'));
251 directoryuri=quote(symget(
'directoryuri'));
252 libname=quote(symget(
'libname'));
253 libref=quote(symget(
'libref'));
254 IsPreassigned=quote(symget(
'IsPreassigned'));
255 prototypeuri=quote(symget(
'prototypeuri'));
258 libdesc=tranwrd(symget(
'libdesc'),
'&',
'&');
259 libdesc=tranwrd(libdesc,
'<',
'<');
260 libdesc=tranwrd(libdesc,
'>',
'>');
261 libdesc=tranwrd(libdesc,
"'",
''');
262 libdesc=tranwrd(libdesc,
'"',
'"');
263 libdesc=tranwrd(libdesc,
'0A'x,
' ');
264 libdesc=tranwrd(libdesc,
'0D'x,
' ');
265 libdesc=tranwrd(libdesc,
'$',
'$');
266 libdesc=quote(trim(libdesc));
268 put
"<AddMetadata><Reposid>$METAREPOSITORY</Reposid><Metadata> "/
269 '<SASLibrary Desc=' libdesc
' Engine="BASE" IsDBMSLibname="0" '/
270 ' IsHidden="0" IsPreassigned=' IsPreassigned
' Libref=' libref /
271 ' UsageVersion="1000000" PublicType="Library" name=' libname
'>'/
272 ' <DeployedComponents>'/
273 ' <ServerContext ObjRef=' serveruri
"/>"/
274 ' </DeployedComponents>'/
276 ' <PropertySet Name="ModifiedByProductPropertySet" '/
277 ' SetRole="ModifiedByProductPropertySet" UsageVersion="0" />'/
279 " <Trees><Tree ObjRef=" treeuri
"/></Trees>"/
281 ' <Directory ObjRef=' directoryuri
' />'/
284 ' <Prototype ObjRef=' prototypeuri
'/>'/
285 ' </UsingPrototype>'/
286 '</SASLibrary></Metadata><NS>SAS</NS>'/
287 '<Flags>268435456</Flags></AddMetadata>';
291 proc metadata in= &frefin out=&frefout %
if &mdebug=1 %then verbose ;;
294 %
if &mdebug=1 %then %
do;
296 infile &frefout lrecl=1048576;
300 %put NOTE: Checking to ensure library (&libname) was created;
302 length type uri $256;
303 rc=metadata_pathobj(
"",
"&tree/&libname",
"Library",type,uri);
304 call symputx(
'libtype',type,
'l');
305 call symputx(
'liburi',uri,
'l');
306 %
if &mdebug=1 %then putlog (_all_)(=);;
308 %
if &libtype ne SASLibrary %then %
do;
309 %put %str(ERR)OR: Could not find (&libname) at (&tree)!!;
312 %
else %put NOTE: Library (&libname) successfully created in (&tree)!;
315 %put %str(ERR)OR: Other library engine types are not yet supported!!;
322%
if &mdebug ne 1 %then %
do;
323 filename &frefin clear;
324 filename &frefout clear;
327%mend mm_createlibrary;