Current directory is the default location where SAS will look for input files and write output files unless you specify otherwise.
There are two effective methods to find your current working directory in SAS:
Method 1: Using SAS Macro
%macro cwd;
%let rc=%sysfunc(filename(cwd,.));
%let cwd=%sysfunc(pathname(&cwd));
%put Current Working Directory: &cwd;
%mend;
%cwd
Explanation:
%macro cwd;
: Defines a macro named “cwd”.%let rc=%sysfunc(filename(cwd, .));
: Assigns a fileref named “cwd” to the current directory (represented by “.”). Thefilename
function is used to get the assigned fileref’s path.%let cwd=%sysfunc(pathname(cwd));
: Retrieves the full path of the “cwd” fileref using thepathname
function.%put Current Working Directory: &cwd;
: Prints the retrieved path to the log
Method 2: Using the PATHNAME Function directly
The PATHNAME function is a useful tool in SAS that allows you to retrieve the physical name of an external file or library.
By using the PATHNAME function, you can easily obtain the file’s or library’s physical name, which can be used in various SAS procedures and data steps.
data _null_;
rc = filename('cwd',.);
cwd = pathname('cwd');
put cwd=;
run;
These methods provide the current working directory at the time of execution. If you change your working directory using DLGCDIR or other methods later, you’ll need to rerun these code snippets to get the updated path.