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!
%macro mm_deletestp(
target=
)/*/STORE SOURCE*/;
/**
* Check STP does exist
*/
%local cmtype;
data _null_;
length type uri $256;
rc=metadata_pathobj("","&target",'StoredProcess',type,uri);
call symputx('cmtype',type,'l');
call symputx('stpuri',uri,'l');
run;
%if &cmtype ne ClassifierMap %then %do;
%put NOTE: No Stored Process found at ⌖
%return;
%end;
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!
filename __in temp lrecl=10000;
filename __out temp lrecl=10000;
data _null_ ;
file __in ;
put "<DeleteMetadata><Metadata><ClassifierMap Id='&stpuri'/>";
put "</Metadata><NS>SAS</NS><Flags>268436480</Flags><Options/>";
put "</DeleteMetadata>";
run ;
1
filename __in temp lrecl=10000;
2
filename __out temp lrecl=10000;
3
DATA _null_ ;
4
file __in ;
5
put "<DeleteMetadata><Metadata><ClassifierMap Id='&stpuri'/>";
6
put "</Metadata><NS>SAS</NS><Flags>268436480</Flags><Options/>";
7
put "</DeleteMetadata>";
8
RUN ;
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!
proc metadata in=__in out=__out verbose;run;
1
PROC 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!
/* list the result */
data _null_;infile __out; input; list; run;
1
/* list the result */
2
DATA _null_;
3
INFILE __out;
4
INPUT;
5
list;
6
7
RUN;
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!
filename __in clear;
filename __out clear;
1
filename __in clear;
2
filename __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!
/**
* Check deletion
*/
%local isgone;
data _null_;
length type uri $256;
call missing (of _all_);
rc=metadata_pathobj("","&target",'Note',type,uri);
call symputx('isgone',type,'l');
run;
%if &isgone = ClassifierMap %then %do;
%put %str(ERR)OR: STP not deleted from ⌖
%let syscc=4;
%return;
%end;
%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.
« 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. »
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.