Config files - WerthPADOH/DHI-trial GitHub Wiki
By using a relative file path, "config files" are easy:
- In the project's base directory, create a single SAS program (e.g., "master.sas") that runs all the necessary parts of the project (this is good practice, anyway).
- In the same directory, create another file (e.g., "config.sas") that saves environmental variables and sensitive information as macro variables.
- In the "master" program, paste the change_directory_if_gui macro. Then use
%INCLUDE "config.sas"
to read in the configuration variables. - Use the config variables throughout the project's code. Also, describe in detail what the config file should define (either in the master program, the README, or some other documentation),
- In the .gitignore file (make one if there isn't one), include the line:
config.sas
. This way, people won't accidentally add their configuration files to the repository.
Example
Contents of the config program:
/*---------------------------------
config.sas
---------------------------------*/
%Let secure_path = path/to/directory;
%Let username = jdoe;
%Let password = 123abc;
Contents of the master program:
/*---------------------------------
master.sas
Runs everything
Variables from config.sas
- secure_path
- username
- password
---------------------------------*/
%MACRO change_directory_if_gui;
%Let execpath = %sysget(SAS_EXECFILEPATH);
%If %length(&execpath.) > 0 %then %do;
%Let execname = %sysget(SAS_EXECFILENAME);
%Let execdir_length = %eval(%length(&execpath.) - %length(&execname.) - 1);
%Let execdir = %substr(&execpath., 1, &execdir_length.);
DATA _NULL_;
rc = system("cd ""&execdir.""");
Run;
%End;
%Mend change_directory_if_gui;
%change_directory_if_gui;
%Include "config.sas";
Line added to .gitignore:
config.sas