Published on :
Général INTERNAL_CREATION

Sans titre

This code is also available in: Deutsch Español Français
This program illustrates the use of the automatic macro variable `_SASPROGRAMFILE` (often available in environments like SAS© Studio or in batch mode). It uses macro string manipulation functions (`%qsubstr`, `%length`, `%scan`) to isolate the file name without its extension or to obtain only the parent directory path.
Data Analysis

Type : INTERNAL_CREATION


The script does not manipulate any data tables; it only interacts with system macro variables.

1 Code Block
MACRO
Explanation :
Displays in the log the content of the `_SASPROGRAMFILE` variable, which contains the full file path.
Copied!
1%put &_SASPROGRAMFILE;
2 Code Block
MACRO
Explanation :
Displays the full path by truncating the last 4 characters (corresponding to the '.sas' extension).
Copied!
1%put %qsubstr(&_SASPROGRAMFILE,1,%LENGTH(&_SASPROGRAMFILE)-4);
2 
3 Code Block
MACRO
Explanation :
Isolates the parent directory by subtracting the length of the file name (found via `%scan` with the '/' delimiter) from the total length of the string.
Copied!
1%put %qsubstr(&_SASPROGRAMFILE,1,%LENGTH(&_SASPROGRAMFILE)-%LENGTH(%scan(&_SASPROGRAMFILE.,-1,'/'))-1);
2 
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 : Nicolas Dupont, 11/07/2017