Published on :
Administration CREATION_INTERNE

Deleting a Library via SAS Metadata

This code is also available in: Español Français
Awaiting validation
Attention : This code requires administrator privileges.
The `mm_deletelibrary` macro automates the deletion of a SAS© library declared in the metadata server (legacy SAS© 9). It first checks for the object's existence via `metadata_resolve`. If the library exists, it dynamically constructs an XML `DeleteMetadata` request and executes it using `PROC METADATA`. Finally, it verifies that the deletion was successful and triggers an error via `%mp_abort` if it was not.
Data Analysis

Type : CREATION_INTERNE


The script itself generates the necessary XML files for `PROC METADATA` via DATA `_NULL_` steps and does not use external data.

1 Code Block
DATA STEP
Explanation :
Checks for the library's existence in the metadata server using the `metadata_resolve` function with the provided name as a parameter. Retrieves the object's URI and type.
Copied!
1DATA _null_;
2 LENGTH type uri $256;
3 rc=metadata_resolve("omsobj:SASLibrary? @Name='&name'",type,uri);
4 call symputx('checktype',type,'l');
5 call symputx('liburi',uri,'l');
6 putlog (_all_)(=);
7RUN;
2 Code Block
DATA STEP Data
Explanation :
Generates the XML request file for the `DeleteMetadata` action. This temporary file contains the deletion instruction targeting the previously identified library URI.
Copied!
1filename &fname1 temp lrecl=10000;
2filename &fname2 temp lrecl=10000;
3DATA _null_ ;
4 file &fname1 ;
5 put "<DeleteMetadata><Metadata><SASLibrary Id='&liburi'/>";
6 put "</Metadata><NS>SAS</NS><Flags>268436480</Flags><Options/>";
7 put "</DeleteMetadata>";
8RUN ;
3 Code Block
PROC METADATA
Explanation :
Executes the `PROC METADATA` procedure to send the generated XML request to the metadata server and perform the deletion.
Copied!
1PROC METADATA in=&fname1 out=&fname2 verbose;RUN;
4 Code Block
DATA STEP
Explanation :
Verifies post-execution if the library still exists by re-querying the metadata server with the URI. The result is stored in the `isgone` macro variable.
Copied!
1DATA _null_;
2 LENGTH type uri $256;
3 call missing (of _all_);
4 rc=metadata_resolve("omsobj:SASLibrary? @Id='&liburi'",type,uri);
5 call symputx('isgone',type,'l');
6RUN;
5 Code Block
Macro Call
Explanation :
Calls the `%mp_abort` utility macro to stop execution and report an error if the library is still detected (deletion failure).
Copied!
1%mp_abort(iftrue=(&isgone = SASLibrary)
2 ,mac=&sysmacroname
3 ,msg=%str(Library (&name) NOT deleted)
4)
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Allan Bowe


Banner
Expert Advice
Expert
Simon
Expert SAS et fondateur.
« It is vital to remember that this process only removes the logical definition of the library from the SAS Metadata Server. It does not delete the physical .sas7bdat files from the file system or the schemas from the external database (e.g., Oracle or SQL Server). »