/** @file @brief Create a Document object in a metadata folder @details Document objects are useful for storing properties in metadata. This macro is idempotent - it will not create an object with the same name in the same location, twice. Note - the filerefs are left open, to enable inspection after running the macro (or importing into an xmlmap if needed). usage: %mm_createdocument(tree=/User Folders/sasdemo ,name=MyNote)

SAS Macros

@li mp_abort.sas @li mf_verifymacvars.sas @param [in] tree= The metadata folder uri, or the metadata path, in which to create the document. This must exist. @param [in] name= Document object name. Avoid spaces. @param [in] desc= Document description (optional) @param [in] textrole= TextRole property (optional) @param [in] frefin= fileref to use (enables change if there is a conflict) @param [out] frefout= fileref to use (enables change if there is a conflict) @param [in] mDebug= set to 1 to show debug messages in the log @author Allan Bowe **/ %macro mm_createdocument( tree=/User Folders/sasdemo ,name=myNote ,desc=Created by &sysmacroname ,textrole= ,frefin=mm_in ,frefout=mm_out ,mDebug=1 ); %local mD; %if &mDebug=1 %then %let mD=; %else %let mD=%str(*); %&mD.put Executing &sysmacroname..sas; %&mD.put _local_; %mp_abort(iftrue= (%mf_verifymacvars(tree name)=0) ,mac=&sysmacroname ,msg=%str(Empty inputs: tree name) ) /** * check tree exists */ data _null_; length type uri $256; rc=metadata_pathobj("","&tree","Folder",type,uri); call symputx('type',type,'l'); call symputx('treeuri',uri,'l'); run; %mp_abort( iftrue= (&type ne Tree) ,mac=mm_createdocument.sas ,msg=Tree &tree does not exist! ) /** * Check object does not exist already */ data _null_; length type uri $256; rc=metadata_pathobj("","&tree/&name","Note",type,uri); call symputx('type',type,'l'); call symputx('docuri',uri,'l'); putlog (_all_)(=); run; %if &type = Document %then %do; %put Document &name already exists in &tree!; %return; %end; /** * Now we can create the document */ filename &frefin temp; /* write header XML */ data _null_; file &frefin; name=quote("&name"); desc=quote("&desc"); textrole=quote("&textrole"); treeuri=quote("&treeuri"); put "$METAREPOSITORY"/ '"/ " "/ ' ' / ''/ /*URI="Document for public note" */ ""/ "SAS"/ "268435456"; run; filename &frefout temp; proc metadata in= &frefin out=&frefout verbose; run; %if &mdebug=1 %then %do; /* write the response to the log for debugging */ data _null_; infile &frefout lrecl=1048576; input; put _infile_; run; %end; %mend mm_createdocument;