Reputation: 1729
I'm attempting to port some SAS code from Windows to Linux. The original code that runs on windows has settings whereby a symbolic reference called "drive" is hard coded to a specific directory such as "C:\SAS", however if I want to move the file structure to Linux I need this symbolic reference to be relative to the directory containing the .sas file that I'm running. Is it possible to query what SAS thinks is the directory containing the .sas file or to set this symbolic reference, relative to the .sas-file contaning directory.
Here is an example. For info both ./multi_use/datetime.sas and ./info do exist
Proc options option=work;
run;
* This first version works but is hard coded
*%let drive=%str(C:\SAS);
* This version does not work, attempting to set the symbolic reference, relatively.
* This is an attempt to set the symbolic reference "drive" such that is the actual
* directory that the controlling .sas file is located in
%let drive=%str(.);
*********************************************************;
%include "&drive/multi_use/datetime.sas";
libname info "&drive/info";
Upvotes: 1
Views: 1186
Reputation: 8513
SAS has no built in way that will tell you the path/filename of the file it is currently executing.
If you are in your home directory when you launch SAS and tell it to run a file in a different folder (eg. /tmp/myfile.sas), then the current working directory (CWD) that SAS uses will be your home directory. For example:
cd ~
sas /tmp/myfile.sas
In the above example, if myfile.sas has a the following statement:
%include "blah.sas";
... it will be looking for blah.sas in your home directory (~/blah.sas), not in the same folder as the file you called (/tmp/blah.sas) because the CWD default to wherever you launched SAS from.
If you wanted to make it work, you can change the CWD of SAS to the /tmp folder by issuing the following command in your SAS session:
x cd /tmp; * SET CWD TO THE RELATIVE PATH;
Note that if you are calling SAS via a script then the script may change the path prior to launching SAS and the above may not apply.
Note that I haven't tested the above as I don't currently have access to SAS in a linux environment.
Upvotes: 1
Reputation:
If your access has been set-up to issue OS-level commands then you can probably knock something up. [I don't have access to submit OS commands so can't help much]
Refer to the SAS File I/O section in Functions and CALL Routines by Category which will provide some handy functions to achieve what your are trying to do.
Of particular interest for your situation would be the following:
FILENAME Function see 3rd example towards the end of the page demonstrating how to use ls
.
[the following would not require OS commands:]
I would also recommend running proc options ; run;
and examine the log to figure out what is SAS seeing as its home directory. You can set the path for your SAS program as relative to that.
See GETOPTION Function
Upvotes: 1