Published on :
Macro CREATION_INTERNE

OS Path Variables Management

This code is also available in: Deutsch Español Français
Awaiting validation
The `%os_fvars` macro is designed to dynamically generate SAS© global macro variables that point to specific directory paths. It uses existing global macro variables like `_projpre` (project prefix), `_divider` (OS directory separator), and `_suffix` (path suffix). The `projpath` argument allows specifying subdirectories, where directory levels are separated by colons (':'). These colons are then replaced by the appropriate directory separator (`_divider`) for the current operating system. The macro ensures that the global macro variable is created with the name specified by the `mvar` argument and displays an informative note in the SAS© log to confirm the creation and the final value of the variable.
Data Analysis

Type : CREATION_INTERNE


The `DATA _NULL_` step manipulates character strings to construct a file path based on existing macro variables and arguments passed to the macro. No data is read or processed from external sources or SASHELP tables directly in this script. The main output is the creation of a global macro variable.

1 Code Block
DATA STEP Data
Explanation :
This block defines the `%os_fvars` macro which takes two arguments: `mvar` for the name of the global macro variable to create, and `projpath` for the project's relative path. The macro declares the `mvar` variable as global. Inside a `DATA _NULL_` step, it determines the `path`: if `projpath` is empty, `path` is constructed from `_projpre` and `_suffix`. Otherwise, it incorporates `_divider` and replaces the ':' characters in `projpath` with `_divider`. `call symput` is then used to create the global macro variable with the constructed name and path value. `PUT` messages are generated in the SAS log to confirm the variable's creation.
Copied!
1 %macro os_fvars (mvar=, projpath=);
2 
3 %** SETUP GLOBAL MACRO VARIABLE ***;
4 %global &mvar;
5 DATA _null_;
6 mvar=upcase("&mvar");
7 %IF &projpath= %THEN %DO;
8 path="&_projpre"||"&_suffix";
9 %END;
10 %ELSE %DO;
11 path="&_projpre"||"&_divider"||trim(left(tranwrd("&projpath",":","&_divider")))
12 ||"&_suffix";
13 %END;
14 call symput(mvar,trim(left(path)));
15 put "NOTE: os_fvars macro has set-up the following global macro variable:-";
16 put "NOTE: " mvar ": " path;
17 RUN;
18 
19 %mend os_fvars;
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.