Published on :
Administration INTERNAL_CREATION

Deleting a Stored Process via Metadata

This code is also available in: Deutsch Español Français
Awaiting validation
Attention : This code requires administrator privileges.
This macro, `mm_deletestp`, is designed to interact with the SAS© metadata server to delete a specific Stored Process. It takes the full path of the Stored Process (`target=`) as a parameter. The macro begins by checking for the existence of the Stored Process using the `metadata_pathobj` function. If the Stored Process is not found (or if the object is not of type 'ClassifierMap'), a NOTE message is issued and the macro terminates. If the Stored Process is found, the macro generates a temporary XML document containing the metadata deletion instructions for the `ClassifierMap` object corresponding to the Stored Process. This XML request is then submitted to the metadata server via `PROC METADATA`. Once the operation is executed, the macro reads and displays the result of `PROC METADATA` in the SAS© log. Finally, the macro performs a post-deletion check to ensure that the Stored Process has been successfully removed from the metadata. In case of deletion failure (if the object is still present), an error message is issued and the `syscc` system variable is updated to indicate a failure.
Data Analysis

Type : INTERNAL_CREATION


The macro primarily interacts with the SAS metadata server to manage Stored Processes. It does not directly consume external data or SASHELP datasets for its main deletion operation. The data processed are metadata information generated and managed by the SAS system itself.

1 Code Block
DATA STEP (metadata_pathobj) and Macro IF
Explanation :
This block initializes the `mm_deletestp` macro and performs an initial verification step. It uses a `DATA _NULL_` step with the `metadata_pathobj` function to query the metadata server. The goal is to determine if a 'StoredProcess' exists at the path specified by the `&target` parameter. The type (`type`) and URI (`uri`) of the found object are stored in macro variables. If the object is not identified as a 'ClassifierMap' (internal type for Stored Processes), a note is issued and the macro terminates, signaling the absence of the Stored Process.
Copied!
1%macro mm_deletestp(
2 target=
3)/*/STORE SOURCE*/;
4 
5/**
6 * Check STP does exist
7 */
8%local cmtype;
9DATA _null_;
10 LENGTH type uri $256;
11 rc=metadata_pathobj("","&target",'StoredProcess',type,uri);
12 call symputx('cmtype',type,'l');
13 call symputx('stpuri',uri,'l');
14RUN;
15%IF &cmtype ne ClassifierMap %THEN %DO;
16 %put NOTE: No Stored Process found at ⌖
17 %return;
18%END;
2 Code Block
DATA STEP (XML Generation) Data
Explanation :
This block prepares for deletion by allocating two temporary filerefs (`__in` and `__out`) for the input and output of the `PROC METADATA` procedure. Then, a `DATA _NULL_` step generates a formatted XML string directly into the `__in` file. This string represents a metadata deletion request targeting the 'ClassifierMap' object whose ID is contained in the `&stpuri` macro variable, thus preparing the instruction for the metadata server.
Copied!
1filename __in temp lrecl=10000;
2filename __out temp lrecl=10000;
3DATA _null_ ;
4 file __in ;
5 put "<DeleteMetadata><Metadata><ClassifierMap Id='&stpuri'/>";
6 put "</Metadata><NS>SAS</NS><Flags>268436480</Flags><Options/>";
7 put "</DeleteMetadata>";
8RUN ;
3 Code Block
PROC METADATA
Explanation :
The `PROC METADATA` procedure is executed to submit the previously generated XML request (contained in `__in`) to the SAS metadata server. The `verbose` option ensures that maximum information about the execution and result of the request is logged, with the output redirected to the temporary file `__out`.
Copied!
1PROC METADATA in=__in out=__out verbose;RUN;
4 Code Block
DATA STEP (File Reading)
Explanation :
This block is a simple `DATA _NULL_` step whose purpose is to read and display the content of the temporary `__out` file in the SAS log. This allows viewing the detailed response from the metadata server following the deletion attempt.
Copied!
1/* list the result */
2DATA _null_;
3INFILE __out;
4INPUT;
5list;
6 
7RUN;
8 
5 Code Block
SAS Global Statement
Explanation :
These `filename CLEAR` statements are essential instructions to properly release the temporary filerefs `__in` and `__out` that have been used. This is good practice to avoid unnecessary resource retention and potential conflicts in subsequent SAS executions.
Copied!
1filename __in clear;
2filename __out clear;
6 Code Block
DATA STEP (metadata_pathobj) and Macro IF
Explanation :
This last block performs a crucial check after the deletion attempt. It again uses `metadata_pathobj` to ensure that the Stored Process (`&target`) has been successfully removed from the metadata. If the object is still found and identified as a 'ClassifierMap', an error message is generated in the log, the `syscc` system variable is set to 4 (indicating an error), and the macro terminates to signal deletion failure. The `%mend` marks the end of the `mm_deletestp` macro.
Copied!
1/**
2 * Check deletion
3 */
4%local isgone;
5DATA _null_;
6 LENGTH type uri $256;
7 call missing (of _all_);
8 rc=metadata_pathobj("","&target",'Note',type,uri);
9 call symputx('isgone',type,'l');
10RUN;
11%IF &isgone = ClassifierMap %THEN %DO;
12 %put %str(ERR)OR: STP not deleted from ⌖
13 %let syscc=4;
14 %return;
15%END;
16 
17%mend mm_deletestp;
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 : Copyright (c) 2001-2006 Rodney Sparapani. This code is distributed under the terms of the GNU General Public License (GPL) version 2 or later.


Banner
Expert Advice
Expert
Simon
Expert SAS et fondateur.
« The mm_deletestp macro illustrates a professional-grade approach to managing the lifecycle of SAS 9 applications. By using PROC METADATA with XML instructions rather than manual deletion via the GUI, you ensure that environment cleanup is automated, repeatable, and auditable. Targeting the ClassifierMap object type is the correct technical choice, as this is the specific metadata class that defines a Stored Process within the Open Metadata Architecture (OMA).

Strategic Insights & Best Practices
The Critical Role of Flags: In the XML request, the <Flags>268436480</Flags> value is vital. This bitmask instructs the server on how to handle associations. A common pitfall in metadata management is leaving "orphan objects" (such as parameter definitions or metadata notes) behind. Using the correct flags ensures a clean deletion that maintains the long-term health of your Metadata Repository.

Defensive Programming & Error Handling: The macro implements a robust double-check: verifying existence before execution and confirming removal afterward. Updating syscc=4 upon failure is an essential practice for production environments; it alerts batch schedulers (like LSF or SAS Job Execution) that an anomaly occurred even if the SAS session itself didn't crash.

Logical vs. Physical Deletion: Be aware that this macro deletes the metadata definition. If your Stored Process points to an external physical file (a .sas file on the server), that file will remain on the disk. For a truly comprehensive cleanup, you might need to pair this macro with an FDELETE command to remove the physical source code. »