Type : CREATION_INTERNE
Les données proviennent directement des fonctions d'interrogation du serveur de métadonnées SAS (metadata_resolve, etc.). Aucune table externe n'est requise.
| 1 | DATA _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; |
| 51 | RUN; |