Published on :
Administration INTERNAL_CREATION

Extracting Deployment Directories from SAS Metadata

This code is also available in: Français
Awaiting validation
Attention : This code requires administrator privileges.
The program connects to a SAS© metadata server via system options. It then uses a DATA STEP with metadata functions (`metadata_resolve`, `metadata_getnobj`, `metadata_getattr`, `metadata_getnasn`) to search for all `Directory` type objects that are deployment directories. For each directory found, it retrieves information about deployed files, associated transformation jobs, and the owners of these jobs. The result is stored in a `work.deployfiles` table and finally displayed with a `PROC PRINT`.
Data Analysis

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 Code Block
OPTIONS
Explanation :
This block configures the connection parameters to the SAS metadata server. It defines the server, port, user, password, repository, and protocol to use. These options are essential for metadata functions to communicate with the server.
Copied!
1options
2 metaserver="meta.demo.sas.com"
3 metaport=8561
4 metauser="sasadm @saspw"
5 metapass="password"
6 metarepository=Foundation
7 metaprotocol=BRIDGE;
2 Code Block
DATA STEP Data
Explanation :
This DATA STEP is the core of the program. It queries SAS metadata to find deployment directories via an 'omsobj' query. Using specific metadata functions (`metadata_resolve`, `metadata_getnobj`, etc.), it navigates through object associations to extract the names of applications, directories, files, jobs, and their owners. The collected information is written to the `work.deployfiles` table.
Copied!
1DATA 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";
45RUN;
3 Code Block
PROC PRINT
Explanation :
This procedure displays the content of the `work.deployfiles` table created in the previous data step. It allows viewing the list of deployment directories and associated information.
Copied!
1PROC PRINT DATA=deployfiles; RUN;
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


Banner
Expert Advice
Expert
Simon
Expert SAS et fondateur.
« 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. »