Here is the code I promised a couple weeks ago. This macro get_stpcode_via_xml is called from inside a "fairly" standard another macro which uses metadata functions to find objects using code like
metadata_getnobj("omsobj:ClassifierMap?@Id contains '.'",obj_count,obj_uri);
...
rc = metadata_getattr(obj_uri, 'publictype', publictype_nm);
and then and restricting parsing to publictype_nm='StoredProcess'
/* Macro get_stpcode_via_xml uses proc metadata to extract the source code
*of a stored process for a specific uri and cleans xml escape strings
* --------------------------------------------------------------------------------*/
%macro get_stpcode_via_xml(text_uri=, out_table=stp_code
, stp_name=, parent_name=, fullpath_txt=, source_code_outpath=,
MetadataUpdated_dttm=);
/* debug:
%put CALLING: get_stpcode_via_xml(&=text_uri &=out_table. ;
%put &=stp_name= &=parent_name ;
%put &=fullpath_txt ;
%put &=source_code_outpath;
%put &=MetadataUpdated_dttm.);*/
filename _in_xml TEMP;
filename _out_xml TEMP;
data _null_;
length string $100;
string=' <TextStore Id="'||"&text_uri."||'"/>';
file _in_xml;
put '<GetMetadata>'
/ ' <Metadata>'
/ string
/ ' </Metadata>'
/ ' <Ns>SAS</Ns>'
/ ' <flags>8</flags>'
/ ' <Options/>'
/ ' </GetMetadata>'
/;
run;
proc metadata in=_in_xml out=_out_xml header=none ;
run;
data &out_table.(keep=uri code_txt);
length code_txt $1024;
/* Code lines are in a very long string and separated by 
 */
infile _out_xml dlmstr='
' recfm=V lrecl=16000000 flowover end=eof;
/* output to .sas file */
file stp_file;
retain uri "&text_uri." now ;
input code_txt @@;
%gen_stp_header_text
if eof and index(code_txt,'TextRole="StoredProcessSourceCode"') then delete;
/* translate tab-marker to blanks */
code_txt=tranwrd(code_txt,'	','09'x);
code_txt=tranwrd(code_txt,'&','&');
code_txt=tranwrd(code_txt,'"','"');
put code_txt $char.;
run;
filename _in_xml clear;
filename _out_xml clear;
%mend get_stpcode_via_xml;
/* test ...
%get_stpcode_via_xml(text_uri=A5JGVV7O.AG002RRL);
/* The code calls another macro to write some information into the output .sas file using this macro*/
%macro gen_stp_header_text;
if _n_=1 then do;
now = datetime();
/* write header */
put "/* Code for STP: &stp_name.*/";
put "/* STP Location: &fullpath_txt.*/";
put "/* MetadataUpdated: &MetadataUpdated_dttm. Metadata Id : &textstore_uri.*/";
put "/* STP Location: &fullpath_txt.*/";
put "/* Code Extracted on : " now datetime. " */";
put "/* -------------------------------------------------------------------------*/";
/* find StoredText=*/
findpos1=index(code_txt,'StoredText');
/* skip over Stored Text= */
code_txt=substrn(code_txt,findpos1+12);
end;
%mend gen_stp_header_text;
... View more