Published on :
Administration CREATION_INTERNE

Stored Process Source Code Extraction via Metadata

This code is also available in: Deutsch Español Français
Attention : This code requires administrator privileges.
This program uses SAS© Metadata Interface (OMF) functions to search for all Stored Process objects (ClassifierMap) containing a 'SourceCode' note. It retrieves the source code text and writes it to the SAS© log. The script also includes commented logic to perform find-and-replace operations on the source code and update the metadata. Note: This code is specific to environments with a SAS© 9 metadata server (legacy compatibility).
Data Analysis

Type : CREATION_INTERNE


Data comes directly from SAS metadata server query functions (metadata_resolve, etc.). No external tables are required.

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