diff --git a/all.sas b/all.sas index 629b233..52c0a47 100644 --- a/all.sas +++ b/all.sas @@ -7601,6 +7601,98 @@ run; %return; %end; +%mend; +/** + @file + @brief Deletes a library by Name + + @details Used to delete a library. + Usage: + + %* create a library in the home directory ; + %mm_createlibrary( + libname=My Temp Library, + libref=XXTEMPXX, + tree=/User Folders/&sysuserid, + directory=%sysfunc(pathname(work)) + ) + + %* delete the library ; + %mm_deletelibrary(name=My Temp Library) + + After running the above, the following will be shown in the log: + + ![](https://i.imgur.com/Y4Tog24.png) + + @param [in] name= the name (not libref) of the library to be deleted + +

SAS Macros

+ @li mf_getuniquefileref.sas + @li mp_abort.sas + + + @version 9.4 + @author Allan Bowe + +**/ + +%macro mm_deletelibrary( + name= +)/*/STORE SOURCE*/; + + +/** + * Check if library exists and get uri + */ +data _null_; + length type uri $256; + rc=metadata_resolve("omsobj:SASLibrary?@Name='&name'",type,uri); + call symputx('checktype',type,'l'); + call symputx('liburi',uri,'l'); + putlog (_all_)(=); +run; +%if &checktype ne SASLibrary %then %do; + %put &sysmacroname: Library (&name) was not found, and so will not be deleted; + %return; +%end; + +%local fname1 fname2; +%let fname1=%mf_getuniquefileref(); +%let fname2=%mf_getuniquefileref(); + +filename &fname1 temp lrecl=10000; +filename &fname2 temp lrecl=10000; +data _null_ ; + file &fname1 ; + put ""; + put "SAS268436480"; + put ""; +run ; +proc metadata in=&fname1 out=&fname2 verbose;run; + +/* list the result */ +data _null_;infile &fname2; input; list; run; + +filename &fname1 clear; +filename &fname2 clear; + +/** + * Check deletion + */ +%local isgone; +data _null_; + length type uri $256; + rc=metadata_resolve("omsobj:SASLibrary?@Id='&liburi'",type,uri); + call symputx('isgone',type,'l'); +run; + +%mp_abort(iftrue=(&isgone = SASLibrary) + ,mac=&sysmacroname + ,msg=%str(Library (&name) NOT deleted) +) + +%put &sysmacroname: Library &name (&liburi) was successfully deleted; + %mend; /** @file mm_deletestp.sas @@ -8453,6 +8545,39 @@ run; options metarepository=&oldrepo; %end; +%mend;/** + @file + @brief Compares the metadata of a library with the physical tables + + @param [out] prefix the dataset to create that contains the list of libraries + @param mDebug set to anything but 0 to show debug messages in the log + + @test Create a temporary library as follows: + + % + + @details Creates a series of output tables that show the differences between + metadata and physical tables. + Each output can be created with an optional prefix. + + + + + @version 9.3 + @author Allan Bowe + +**/ + +%macro mm_getlibmetadiffs + prefix=metadiff + ,mdebug=0 +)/*/STORE SOURCE*/; + +%if &mdebug = 0 %then %let mdebug=*; + +&mdebug %put _local_; + + %mend;/** @file @brief Creates a dataset with all metadata libraries