Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mm_deletelibrary.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Deletes a library by Name
4
5 @details Used to delete a library.
6 Usage:
7
8 %* create a library in the home directory ;
9 %mm_createlibrary(
10 libname=My Temp Library,
11 libref=XXTEMPXX,
12 tree=/User Folders/&sysuserid,
13 directory=%sysfunc(pathname(work))
14 )
15
16 %* delete the library ;
17 %mm_deletelibrary(name=My Temp Library)
18
19 After running the above, the following will be shown in the log:
20
21 ![](https://i.imgur.com/Y4Tog24.png)
22
23 @param [in] name= () the name (not libref) of the library to be deleted
24
25 <h4> SAS Macros </h4>
26 @li mf_getuniquefileref.sas
27 @li mp_abort.sas
28
29
30 @version 9.4
31 @author Allan Bowe
32
33**/
34
35%macro mm_deletelibrary(
36 name=
37)/*/STORE SOURCE*/;
38
39
40/**
41 * Check if library exists and get uri
42 */
43data _null_;
44 length type uri $256;
45 rc=metadata_resolve("omsobj:SASLibrary?@Name='&name'",type,uri);
46 call symputx('checktype',type,'l');
47 call symputx('liburi',uri,'l');
48 putlog (_all_)(=);
49run;
50%if &checktype ne SASLibrary %then %do;
51 %put &sysmacroname: Library (&name) was not found, and so will not be deleted;
52 %return;
53%end;
54
55%local fname1 fname2;
56%let fname1=%mf_getuniquefileref();
57%let fname2=%mf_getuniquefileref();
58
59filename &fname1 temp lrecl=10000;
60filename &fname2 temp lrecl=10000;
61data _null_ ;
62 file &fname1 ;
63 put "<DeleteMetadata><Metadata><SASLibrary Id='&liburi'/>";
64 put "</Metadata><NS>SAS</NS><Flags>268436480</Flags><Options/>";
65 put "</DeleteMetadata>";
66run ;
67proc metadata in=&fname1 out=&fname2 verbose;run;
68
69/* list the result */
70data _null_;infile &fname2; input; list; run;
71
72filename &fname1 clear;
73filename &fname2 clear;
74
75/**
76 * Check deletion
77 */
78%local isgone;
79data _null_;
80 length type uri $256;
81 call missing (of _all_);
82 rc=metadata_resolve("omsobj:SASLibrary?@Id='&liburi'",type,uri);
83 call symputx('isgone',type,'l');
84run;
85
86%mp_abort(iftrue=(&isgone = SASLibrary)
87 ,mac=&sysmacroname
88 ,msg=%str(Library (&name) NOT deleted)
89)
90
91%put &sysmacroname: Library &name (&liburi) was successfully deleted;
92
93%mend mm_deletelibrary;