Published on :

Extracting Job Source Paths from Metadata

This code is also available in: Deutsch Español Français
Awaiting validation
Attention : This code requires administrator privileges.
This program connects to a SAS© 9 metadata server (via `metaserver`, `metaport`, etc. options) to inventory all 'Job' type objects. For each Job found, it navigates through metadata associations to identify the associated source code file ('SourceCode') and its parent directory ('Directories'), in order to reconstruct the complete file path.
Data Analysis

Type : EXTERNAL


Data comes from the SAS Metadata Server (SAS 9). The script uses metadata interface functions (`metadata_resolve`, `metadata_getnobj`, `metadata_getattr`, `metadata_getnasn`) to extract information.

1 Code Block
OPTIONS
Explanation :
Configuration of the connection to the SAS 9 metadata server. Identifiers (here 'sasadm') and the server address are specified to allow querying.
Copied!
1options metaserver="meta.demo.sas.com"
2 metaport=8561
3 metauser="sasadm @saspw"
4 metapass="password"
5 metarepository=Foundation
6 metaprotocol=bridge;
2 Code Block
DATA STEP Data
Explanation :
Main Data step that performs the extraction. It initiates a search for 'Job' objects (Note: the search string `omsobj:Job?...` seems to contain a file injection artifact from the original prompt, probably replacing `@Id`). It then loops through each found job to retrieve its name, the linked source file object, and then the directory of that file, concatenating everything to form the `source` path.
Copied!
1DATA SOURCE;
2 
3 keep job_name SOURCE; /* Retain only the job name and it's source code full path. */
4 
5/* Initialize variables. */
6 
7 LENGTH type id job_uri job_name file_uri file_name dir_uri path $ 50;
8 call missing (of _character_);
9 
10 obj="omsobj:Job? @code_sas_json/_render_idcolumn.json contains '.'"; /* Search critera for Jobs. */
11 
12 job_count=metadata_resolve(obj,type,id); /* Count all jobs. Only run loop if jobs exist. */
13 
14 IF job_count > 0 THEN DO i=1 to job_count; /* Loop: For each job found, get attributes and associations. */
15 rc=metadata_getnobj(obj,i,job_uri);
16 rc=metadata_getattr(job_uri,"Name",job_name); /* Get job name. */
17 rc=metadata_getnasn(job_uri,"SourceCode",1,file_uri); /* Get file Metadata object id. */
18 rc=metadata_getattr(file_uri,"Name",file_name); /* Get file name. */
19 rc=metadata_getnasn(file_uri,"Directories",1,dir_uri); /* Get directory Metadata object id. */
20 rc=metadata_getattr(dir_uri,"DirectoryName",path); /* Get path to directory. */
21 SOURCE=catx('/',path,file_name); /* combine directory path and file name to create full path to file.*/
22 OUTPUT;
23 END; /* End loop. */
24 ELSE put "WARN: No jobs found in Metadata."; /* If no jobs are found, write a message to the log. */
25RUN;
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.