Published on :

Extracting Stored Process Source Code (SAS Metadata)

This code is also available in: Deutsch Español Français
Attention : This code requires administrator privileges.
The script uses the SAS© Open Metadata Interface (metadata_* functions) to search for 'ClassifierMap' objects corresponding to Stored Processes. It then iterates through associated notes to find the one named 'SourceCode' and extracts the stored text. The script also includes commented logic to modify and update this source code directly in the metadata. Note: This script is specific to the SAS© 9 metadata architecture and does not apply to native SAS© Viya content (SAS© Content).
Data Analysis

Type : EXTERNE


Data is dynamically extracted from the SAS metadata server via function calls (metadata_resolve, metadata_getnobj, etc.).

1 Code Block
DATA STEP
Explanation :
DATA _NULL_ step iterating through metadata objects to extract and display Stored Process source code.
Copied!
1DATA _null_;
2 
3/* Initialize the variables. */
4 
5 LENGTH program newprog $ 32587 type id $ 50
6 sp_uri $ 38 note_uri $ 34 note_name $ 255;
7 call missing(of _character_);
8 
9/* Define a query that will return only Stored Process */
10/* objects with an associated source code TextStore object. */
11 
12sp_obj="omsobj:ClassifierMap?ClassifierMap[ @PublicType='StoredProcess'][Notes/TextStore[ @Name='SourceCode']]";
13 
14/* Count how many objects meet that query. */
15 
16 sp_count=metadata_resolve(sp_obj,type,id);
17 
18/* If some exist, gather their information. */
19 IF sp_count > 0 THEN DO i=1 to sp_count;
20 
21/* Get the URI for each Stored Process object found that matches the query. */
22 rc=metadata_getnobj(sp_obj,i,sp_uri);
23 
24/* Count how many notes are associated with the object. */
25 note_count=metadata_getnasn(sp_uri,"Notes",1,note_uri);
26 
27/* If some exist, get their attributes. */
28 IF note_count > 0 THEN DO j=1 to note_count;
29 /* get the URI of the note. */
30 rc=metadata_getnasn(sp_uri,"Notes",j,note_uri);
31 /* get the name of the note. */
32 rc=metadata_getattr(note_uri,"Name",note_name);
33 
34/* If the Note's name is "SourceCode", get it's "StoredText" attribute. */
35 IF note_name="SourceCode" THEN DO;
36 rc=metadata_getattr(note_uri,"StoredText",program);
37 put;
38 put note_uri=; /* Print the URI to the Log */
39 put;
40 put program=; /* Print the program to the log. */
41 /* Optional find and replace code. replace old_text */
42 /* and new_text with the word to replace. */
43 *newprog=tranwrd(program,'old_text','new_text');
44 *rc=metadata_setattr(note_uri,"StoredText",newprog);
45 END;
46 END;
47 END;
48RUN;
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 : Author: Greg Wootton Date: 03DEC2018