The script does not use external data sources or traditional SAS datasets. It interacts directly with the SAS metadata service. The necessary information is either provided as a macro parameter (`target`) or dynamically generated (XML request) within the script itself. No data from SASHELP or other unmanaged sources is required.
1 Code Block
Macro Definition
Explanation : This block defines the SAS macro `%mm_deletedocument`. It is designed to be called with a `target` parameter, which is the full path of the metadata 'Document' object to be deleted.
Explanation : This `DATA STEP _null_` initializes local variables (`type`, `uri`) and uses the `metadata_pathobj` function to query the metadata repository to check the existence of the object specified by `&target` and obtain its type ('Note') and URI. The retrieved information is stored in the macro variables `type` and `stpuri`. If the object is not a 'Document' or is not found, a warning message is issued, and the macro terminates.
Copied!
/**
* Check document exist
*/
%local type;
data _null_;
length type uri $256;
rc=metadata_pathobj("","&target",'Note',type,uri);
call symputx('type',type,'l');
call symputx('stpuri',uri,'l');
run;
%if &type ne Document %then %do;
%put %str(WARN)ING: No Document found at ⌖
%return;
%end;
Explanation : This block prepares temporary files for the input (`__in`) and output (`__out`) of the `proc metadata` procedure. A `DATA STEP _null_` is used to generate an XML metadata deletion document, including the URI of the document to be deleted (`&stpuri`), and write it to the `__in` file. The `proc metadata` is then invoked with these files to submit the deletion request to the SAS metadata server.
Copied!
filename __in temp lrecl=10000;
filename __out temp lrecl=10000;
data _null_ ;
file __in ;
put "<DeleteMetadata><Metadata><Document Id='&stpuri'/>";
put "</Metadata><NS>SAS</NS><Flags>268436480</Flags><Options/>";
put "</DeleteMetadata>";
run ;
proc metadata in=__in out=__out verbose;run;
1
filename __in temp lrecl=10000;
2
filename __out temp lrecl=10000;
3
DATA _null_ ;
4
file __in ;
5
put "<DeleteMetadata><Metadata><Document Id='&stpuri'/>";
6
put "</Metadata><NS>SAS</NS><Flags>268436480</Flags><Options/>";
7
put "</DeleteMetadata>";
8
RUN ;
9
PROC METADATA in=__in out=__out verbose;RUN;
4 Code Block
DATA STEP
Explanation : This `DATA STEP _null_` reads and displays the content of the `__out` file, which contains the metadata server's response following the deletion operation. This allows viewing the operation status. Then, the fileref definitions for `__in` and `__out` are cleared.
Copied!
/* list the result */
data _null_;infile __out; input; list; run;
filename __in clear;
filename __out clear;
1
/* list the result */
2
DATA _null_;INFILE __out; INPUT; list; RUN;
3
4
filename __in clear;
5
filename __out clear;
5 Code Block
DATA STEP
Explanation : This block performs a final check to ensure that the document has been successfully deleted. The `metadata_pathobj` function is called again to check for the existence of the object at `&target`. If the document is still present (`&isgone = Document`), an error message is displayed, the system return code (`syscc`) is set to 4, and the macro terminates, indicating that the deletion failed.
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 = Document %then %do;
%put %str(ERR)OR: Document not deleted from ⌖
%let syscc=4;
%return;
%end;
%put %str(ERR)OR: Document not deleted from ⌖
13
%let syscc=4;
14
%return;
15
%END;
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.
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.