Regardless of the environment in which you run SAS (whether it is SAS® Foundation, SAS® Studio, or SAS® Enterprise Guide®), SAS uses a default location on your host system as a working directory. When you do not specify the use of a different directory within your code, the default location is where SAS stores output.
Beginning with SAS® 9.4 TS1M4, you can use a new DATA step function, DLGCDIR, to change the location for your working directory. You can use this function in Microsoft Windows or UNIX/Linux environments.
Make sure that any directory that you specify with the DLGCDIR function is an existing directory that you have Write or Update access to.
Finding Out What Your Current Directory Is
To determine what your current working directory in SAS is, submit the following code:
data _null_; rc=dlgcdir(); put rc=; run;
Changing Your Windows Directory
The following sample code for Windows sets the working directory in SAS as the TEMP folder on your C: drive:
data _null_; rc=dlgcdir("c:\temp"); put rc=; run;
Changing Your Linux Directory
This sample code (for a Linux environment) changes the working directory in SAS to /u/your/linux/directory:
data _null_; rc=dlgcdir("/u/your/linux/directory"); put rc=; run;
Changing Your Directory: Other Tips
The DLGCDIR function temporarily changes the working directory for the current SAS or client session. However, you can create an autoexec file that contains the DATA step code that uses the DLGCDIR function. The autoexec file then executes the code each time you invoke SAS.
In most situations, it is still recommended that you specify the intended target directory for the Output Delivery System (ODS) and in other SAS statements. For example, when you use the ODS HTML statement, you should specify the target directory with the PATH option, as shown here:
ods html path="c:\temp" (url=none) file="sasoutput.html";
Similarly, with the ODS PDF statement, you should specify the target directory with the FILE option, as shown here:
ods pdf file="c:\temp\sasoutput.pdf";
I hope you've found this post helpful.