Published on :
Macro EXTERNE

Directory Inspection using SAS Macro Functions

This code is also available in: Deutsch Español Français
This script uses system interface functions (SCL functions) encapsulated in %sysfunc to interact with the file system. It assigns a fileref to a folder path, opens it, counts the number of elements, retrieves the name of the last element, and then closes everything properly.
Data Analysis

Type : EXTERNE


The script queries the OS file system. It depends on an external macro-variable '&path' to define the target path.

1 Code Block
MACRO
Explanation :
Uses low-level functions (filename, dopen, dnum, dread, dclose) via %sysfunc to manipulate a directory. Displays the number of files and the name of the last file in the log.
Copied!
1*m205d09;
2 
3%let rc=%sysfunc(filename(fileref,&path\subfolder));
4%*let rc=%sysfunc(filename(fileref,S:\workshop\subfolder));
5 
6%let did=%sysfunc(dopen(&fileref));
7%let count=%sysfunc(dnum(&did));
8 
9%put &=fileref &=did &=count memname=%sysfunc(dread(&did,&count));
10 
11%let didc=%sysfunc(dclose(&did));
12%let rc=%sysfunc(filename(fileref));
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.