L’extraction du code source via l'interface SAS Open Metadata (OMF) est une technique avancée indispensable pour l'audit massif ou la refonte d'environnements SAS 9. Contrairement à une consultation manuelle, l'interrogation de l'objet ClassifierMap permet d'accéder directement au flux de texte stocké dans l'attribut StoredText de l'objet lié TextStore. Cette approche est particulièrement puissante pour industrialiser des opérations de "rechercher-remplacer" (via TRANWRD) sur l'ensemble de votre catalogue, par exemple pour mettre à jour des chemins de fichiers ou des constantes avant une migration.
Type : EXTERNE
Les données sont extraites dynamiquement du serveur de métadonnées SAS via des appels de fonctions (metadata_resolve, metadata_getnobj, etc.).
| 1 | DATA _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 | |
| 12 | sp_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; |
| 48 | RUN; |