How do I reference the location of my source code file from my sas language program?

Nico Chart_21517
Nico Chart_21517
Altair Employee
edited June 19 in Altair RapidMiner

In batch both, the current working directory (CWD) is inherited from the shell/program/command that invokes the wps command.

When running from Workbench, by default, the current working directory is set to the directory where your eclipse project is stored. You can see and change this setting by looking at the properties of your SLC server (in the subwindow Altair SLC Server Explorer). You will see the initial current directory for server process is set to "${workspace_loc}".

There is a "workspace_loc" and a "project_loc" variable for the location of the current Eclipse project...which at many customer sites is simply a sub-folder of the workspace folder. Unfortunately these eclipse variables cannot be passed into the SAS language run-time environment.

If you set "Set working directory to program directory on code submission" then the initial CWD will be set to the location of your sas language source code file, even if that is not the same as the eclipse project.

If you have %INCLUDE statements in your program using relative paths, it is important that you start the server in the correct directory to allow those %INCLUDE statements to find the files.

Environmental variables SAS_EXECFILEPATH and SAS_EXECFILENAME (also _SASPROGRAMFILE) are generated dynamically by SAS but Altair SLC does not setup these variables or system options.

If you are running your programs in batch you should be able to get the full path to your executing file from the SYSPROCESSNAME automatic variable. But this will not work from the workbench.

SYSIN is set to the script paths.

Alternatively you could do something like:

LIBNAME _pwd_ ".";
%let folder = %nrbquote(%sysfunc(pathname(_pwd_)));
%put folder=&folder.;
libname _pwd_ clear;
%include "&folder./Settings.sas";

when running SLC from the command line and it should pick up your include file that sits next to your source code.

Other points relevant to CWD considerations:

Some special handling of 'cd' is built into the X command so you can use:

X CD 'dirname';

You can make use of these Server properties (from subwindow Altair SLC Server Explorer) to explicitly set the current working directory.

  • Code Submission > Set working directory to program directory on code submission
  • Startup > Initial current directory for server process

System option SASINITIALFOLDER is available.

Unfortunately function DLGCDIR is not currently implemented.

A practicals strategy that some users follow is to set a project location outside of the Workbench altogether, in the .CFG files that are loaded by the SLC compiler whether it is run from Workbench or from batch.

For example, put this in the primary altairslc.cfg file that is shared by all your end-users:

-SET SLC_PROJECT_LOC /sasprogs/projects/master

Then each project may need something like this to initialise the project location:

%let _MyCLIENTPROJECTPATH = "%sysget(SLC_PROJECT_LOC)/MyProject";

Something like that could provide the flexibility to easily override the default projects location when debugging a project copy. I am sure you would want to vary this to suit the operating environment at your site.

Tagged: