Published on :

Creating a Metadata Folder

This code is also available in: Deutsch Español Français
Attention : This code requires administrator privileges.
The `mmx_createmetafolder` macro takes as parameters the folder location (`loc`), the username (`user`), and the password (`pass`) to connect to the metadata server. It retrieves connection information (host and port) from SAS© system options (`metaserver`, `metaport`). A path to an external tool (`sas©-make-folder`) is constructed. The macro then executes this external command via a `DATA _NULL_` statement with the `pipe` option to create the metadata folder using the provided connection information and specified path. After the creation attempt, it uses the `metadata_pathobj` function to verify if the folder has been successfully created. If the folder does not exist, the `mp_abort` macro is called to stop execution and report an error.
Data Analysis

Type : EXTERNAL


The script interacts with the SAS metadata server for folder creation and verification. It uses the system options `metaserver` and `metaport` for connection. Additionally, it executes an external system command (`sas-make-folder`) via the `pipe` instruction, which implies interaction with the underlying operating environment. It does not process traditional external data files (CSV, Excel, etc.) that would not be managed by the script itself or SASHELP libraries.

1 Code Block
MACRO CALL / DATA STEP
Explanation :
This block initializes local macro variables (`host`, `port`, `path`, `connx_string`, `msg`). It retrieves the SAS metadata server host and port via the `getoption` function. It then constructs the connection string (`connx_string`) including the provided credentials, and a path (`path`) to an external `sas-make-folder` tool (the `%mf_loc` macro is an external dependency). A `DATA _NULL_` step is used with the `infile ... pipe` instruction to execute the external `sas-make-folder` command with the defined parameters, in order to create the metadata folder. The command's output is directed to the SAS log via `putlog _infile_`.
Copied!
1%local host port path connx_string msg;
2%let host=%sysfunc(getoption(metaserver));
3%let port=%sysfunc(getoption(metaport));
4%let path=%mf_loc(POF)/tools;
5 
6%let connx_string= -host &host -port &port -user '&user' -password '&pass';
7/* remove directory */
8DATA _null_;
9 INFILE " &path/sas-make-folder &connx_string ""&loc"" 2>&1"
10 pipe lrecl=10000;
11 INPUT;
12 putlog _infile_;
13RUN;
2 Code Block
DATA STEP / MACRO CALL
Explanation :
This block proceeds with folder creation verification and error handling. A `DATA _NULL_` step uses the `metadata_pathobj` function to query the metadata server for the type of object existing at the location specified by `&loc`. The result, indicating the object type (e.g., 'Tree' for a folder), is stored in the local macro variable `foldertype` via `call symputx`. If `foldertype` is not 'Tree', the `%mp_abort` macro (an error-reporting termination macro) is called, indicating that the location was not created correctly.
Copied!
1DATA _null_; /* check tree exists */
2 LENGTH type uri $256;
3 rc=metadata_pathobj("","&loc","Folder",type,uri);
4 call symputx('foldertype',type,'l');
5RUN;
6%let msg=Location (&loc) was not created!!;
7%mp_abort(iftrue= (&foldertype ne Tree)
8 ,mac=&_program..sas
9 ,msg=%superq(msg)
10)
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 : The code refers to several copyright sources: 'Allan Bowe' (author mentioned in the main file's help block), 'Copyright (c) 2001-2006 Rodney Sparapani' (under GNU GPL license, from _version.sas), 'Copyright 2010-2023 HMS Analytical Software GmbH' (from macro_without_brief_tag.sas), and 'Copyright © 2022, SAS Institute Inc.' (from print_macro_parameters.sas and HTML documentation).