When auditing a SAS 9.4 environment, querying the Metadata Server directly via the Data Step is the most powerful way to map relationships between physical assets and logical objects. This specific approach is invaluable for impact analysis, such as identifying which job owners must be notified if a physical deployment directory is moved or decommissioned.
Type : INTERNAL_CREATION
Data is dynamically generated by querying the SAS metadata server using `metadata_*` functions. No external data source is read or required for execution.
| 1 | options |
| 2 | metaserver="my.sas.server" |
| 3 | metaport=8561 |
| 4 | metauser="sasadm @saspw" |
| 5 | metapass="password" |
| 6 | metarepository=Foundation |
| 7 | metaprotocol=BRIDGE; |
| 1 | DATA work.deployfiles; |
| 2 | |
| 3 | /* declare and initialize variables */ |
| 4 | |
| 5 | LENGTH app_name type dir_uri app_uri dir_name file_uri file_name owner trans_uri resp_uri job_name $ 50 id $ 17 dir_path $ 255; |
| 6 | call missing(of _character_); |
| 7 | |
| 8 | /* variables to store to table */ |
| 9 | |
| 10 | keep app_name dir_name dir_path file_name owner job_name; |
| 11 | |
| 12 | dir_obj="omsobj:Directory?Directory[ @build_example_from_doc/SAS Help Center_ A Variable with a User-Defined Format.html Help Center_ Bucket Binning and Weight-of-Evidence Computation.html contains '.'][DeployedComponents/ServerContext]"; |
| 13 | dir_rc=metadata_resolve(dir_obj,type,id); /* Count number of directories with an associated server context. */ |
| 14 | |
| 15 | IF dir_rc > 0 THEN DO n=1 to dir_rc; /* if directories exist, pull data from them. */ |
| 16 | |
| 17 | rc=metadata_getnobj(dir_obj,n,dir_uri); |
| 18 | rc=metadata_getnasn(dir_uri,"DeployedComponents",1,app_uri); |
| 19 | rc=metadata_getattr(app_uri,"Name",app_name); |
| 20 | rc=metadata_getattr(dir_uri,"Name",dir_name); |
| 21 | rc=metadata_getattr(dir_uri,"DirectoryName",dir_path); |
| 22 | |
| 23 | file_rc=metadata_getnasn(dir_uri,"Files",1,file_uri); |
| 24 | |
| 25 | IF file_rc > 0 THEN DO m=1 to file_rc; /* if files are associated with the directory, pull data on them. */ |
| 26 | |
| 27 | rc=metadata_getnasn(dir_uri,"Files",m,file_uri); |
| 28 | rc=metadata_getattr(file_uri,"FileName",file_name); |
| 29 | trans_rc=metadata_getnasn(file_uri,"AssociatedTransformation",1,trans_uri); |
| 30 | |
| 31 | IF trans_rc > 0 THEN DO o=1 to trans_rc; /* if jobs are associated with the files, pull the responsible party of that job. */ |
| 32 | |
| 33 | rc=metadata_getnasn(file_uri,"AssociatedTransformation",o,trans_uri); |
| 34 | rc=metadata_getattr(trans_uri,"Name",job_name); |
| 35 | rc=metadata_getnasn(trans_uri,"ResponsibleParties",1,resp_uri); |
| 36 | rc=metadata_getattr(resp_uri,"Name",owner); |
| 37 | OUTPUT; |
| 38 | END; |
| 39 | ELSE put "INFO: No Associations Found"; |
| 40 | END; |
| 41 | ELSE put "INFO: No Associated Files Found"; |
| 42 | |
| 43 | END; |
| 44 | ELSE put "INFO: No Deployment Directories Found"; |
| 45 | RUN; |
| 1 | PROC PRINT DATA=deployfiles; RUN; |