61%macro mm_createlibrary(
62 libname=My New Library
64 ,libdesc=Created automatically using the mm_createlibrary macro
66 ,tree=/User Folders/sasdemo
68 ,directory=/tmp/somelib
76%
if &mDebug=1 %then %let mD=;
78%&mD.put Executing &sysmacroname..sas;
81%let libref=%upcase(&libref);
88 rc=metadata_resolve(
"omsobj:SASLibrary?@Name='&libname'",type,uri);
89 call symputx(
'checktype',type,
'l');
90 call symputx(
'liburi',uri,
'l');
93%
if &checktype = SASLibrary %then %
do;
94 %put %str(WARN)ING: Library (&liburi) already exists with libname (&libname);
102 length type uri $256;
103 rc=metadata_resolve(
"omsobj:SASLibrary?@Libref='&libref'",type,uri);
104 call symputx(
'checktype',type,
'l');
105 call symputx(
'liburi',uri,
'l');
108%
if &checktype = SASLibrary %then %
do;
109 %put %str(WARN)ING: Library (&liburi) already exists with libref (&libref) ;
117%mm_createfolder(path=&tree)
123 length type uri $256;
124 rc=metadata_pathobj(
"",
"&tree",
"Folder",type,uri);
125 call symputx(
'foldertype',type,
'l');
126 call symputx(
'treeuri',uri,
'l');
128%
if &foldertype ne Tree %then %
do;
129 %put %str(WARN)ING: Tree &tree does not exist!;
136filename &frefin temp;
137filename &frefout temp;
140 &engine=BASE & %mf_verifymacvars(libname libref engine servercontext tree)=0
143 ,msg=%str(Empty inputs: libname libref engine servercontext tree)
146%if &engine=BASE %then %do;
151 length type uri $256;
152 rc=metadata_resolve(
"omsobj:ServerContext?@Name='&ServerContext'",type,uri);
153 call symputx(
'checktype',type,
'l');
154 call symputx(
'serveruri',uri,
'l');
157 %
if &checktype ne ServerContext %then %
do;
158 %put %str(ERR)OR: ServerContext (&ServerContext) does not exist!;
166 length type uri str $256;
167 str=
"omsobj:Prototype?@Name='Library.SAS.Prototype.Name.xmlKey.txt'";
168 rc=metadata_resolve(str,type,uri);
169 call symputx(
'checktype',type,
'l');
170 call symputx(
'prototypeuri',uri,
'l');
173 %
if &checktype ne Prototype %then %
do;
174 %put %str(ERR)OR: Prototype Library.SAS.Prototype.Name.xmlKey.txt not found;
181 %
if %sysfunc(fileexist(&directory))=0 %then %
do;
182 %put %str(ERR)OR: Physical directory (&directory) does not appear to exist!;
190 length type uri $256;
191 rc=metadata_resolve(
"omsobj:Directory?@DirectoryRole='LibraryPath'"
192 !!
" and @DirectoryName='&directory'",type,uri);
193 call symputx(
'checktype',type,
'l');
194 call symputx(
'directoryuri',uri,
'l');
197 %
if &checktype ne Directory %then %
do;
198 %put NOTE: Directory
object does not exist
for (&directory) location;
199 %put NOTE: It will now be created;
203 directory=quote(symget(
'directory'));
204 put
"<AddMetadata><Reposid>$METAREPOSITORY</Reposid><Metadata> "/
205 '<Directory UsageVersion="1000000" IsHidden="0" IsRelative="0"'/
206 ' DirectoryRole="LibraryPath" Name="Path" DirectoryName=' directory
'/>'/
207 "</Metadata><NS>SAS</NS>"/
208 "<Flags>268435456</Flags></AddMetadata>";
211 proc metadata in= &frefin out=&frefout %
if &mdebug=1 %then verbose;;
213 %
if &mdebug=1 %then %
do;
215 infile &frefout lrecl=1048576;
219 %put NOTE: Checking to ensure directory (&directory)
object was created;
221 length type uri $256;
222 rc=metadata_resolve(
"omsobj:Directory?@DirectoryRole='LibraryPath'"
223 !!
" and @DirectoryName='&directory'",type,uri);
224 call symputx(
'checktype2',type,
'l');
225 call symputx(
'directoryuri',uri,
'l');
226 %
if &mdebug=1 %then putlog (_all_)(=);;
228 %
if &checktype2 ne Directory %then %
do;
229 %put %str(ERR)OR: Directory (&directory)
object was NOT created!;
232 %
else %put NOTE: Directory (&directoryuri) successfully created!;
238 %
if %sysevalf(&sysver lt 9.3) %then %
do;
239 %put %str(WARN)ING: Version 9.3 or later required;
248 treeuri=quote(symget(
'treeuri'));
249 serveruri=quote(symget(
'serveruri'));
250 directoryuri=quote(symget(
'directoryuri'));
251 libname=quote(symget(
'libname'));
252 libref=quote(symget(
'libref'));
253 IsPreassigned=quote(symget(
'IsPreassigned'));
254 prototypeuri=quote(symget(
'prototypeuri'));
257 libdesc=tranwrd(symget(
'libdesc'),
'&',
'&');
258 libdesc=tranwrd(libdesc,
'<',
'<');
259 libdesc=tranwrd(libdesc,
'>',
'>');
260 libdesc=tranwrd(libdesc,
"'",
''');
261 libdesc=tranwrd(libdesc,
'"',
'"');
262 libdesc=tranwrd(libdesc,
'0A'x,
' ');
263 libdesc=tranwrd(libdesc,
'0D'x,
' ');
264 libdesc=tranwrd(libdesc,
'$',
'$');
265 libdesc=quote(trim(libdesc));
267 put
"<AddMetadata><Reposid>$METAREPOSITORY</Reposid><Metadata> "/
268 '<SASLibrary Desc=' libdesc
' Engine="BASE" IsDBMSLibname="0" '/
269 ' IsHidden="0" IsPreassigned=' IsPreassigned
' Libref=' libref /
270 ' UsageVersion="1000000" PublicType="Library" name=' libname
'>'/
271 ' <DeployedComponents>'/
272 ' <ServerContext ObjRef=' serveruri
"/>"/
273 ' </DeployedComponents>'/
275 ' <PropertySet Name="ModifiedByProductPropertySet" '/
276 ' SetRole="ModifiedByProductPropertySet" UsageVersion="0" />'/
278 " <Trees><Tree ObjRef=" treeuri
"/></Trees>"/
280 ' <Directory ObjRef=' directoryuri
' />'/
283 ' <Prototype ObjRef=' prototypeuri
'/>'/
284 ' </UsingPrototype>'/
285 '</SASLibrary></Metadata><NS>SAS</NS>'/
286 '<Flags>268435456</Flags></AddMetadata>';
290 proc metadata in= &frefin out=&frefout %
if &mdebug=1 %then verbose ;;
293 %
if &mdebug=1 %then %
do;
295 infile &frefout lrecl=1048576;
299 %put NOTE: Checking to ensure library (&libname) was created;
301 length type uri $256;
302 rc=metadata_pathobj(
"",
"&tree/&libname",
"Library",type,uri);
303 call symputx(
'libtype',type,
'l');
304 call symputx(
'liburi',uri,
'l');
305 %
if &mdebug=1 %then putlog (_all_)(=);;
307 %
if &libtype ne SASLibrary %then %
do;
308 %put %str(ERR)OR: Could not find (&libname) at (&tree)!!;
311 %
else %put NOTE: Library (&libname) successfully created in (&tree)!;
314 %put %str(ERR)OR: Other library engine types are not yet supported!!;
321%
if &mdebug ne 1 %then %
do;
322 filename &frefin clear;
323 filename &frefout clear;
326%mend mm_createlibrary;