Skip to content

sasjs run

The sasjs run command enables developers to submit SAS code for execution from the commandline.

The log will be returned as a file in the current directory. The source file must have a ".sas" extension.

Note - an additional variable macro variable will be added by the adapter, with the value of the target appLoc and the filename (equivalent to %let _program=/My/AppLoc/;). This is actually added as a session variable, so will not be visible in the logs.


Before using this command, you will need to install the SASJS CLI and add a deployment target.


sasjs run <sourcecode> [additional arguments]

<sourcecode> can be a local file path or a URL.

Additional arguments may include:

  • --log (alias -l) - The full or relative (to the folder in which the command is invoked) path to the log file being created. If ommitted, the log will be created in the current directory, with a timestamp.

  • --source (alias -s) - Path to a JSON file that can be used to inject macro variables into the session. Useful for running existing programs in a "job like" fashion. The JSON file should have the following structure: {"macroVars": {"varname": "value", "var2": "val2"}}. This will result in the following code being injected into the session:

%let varname=value;
%let var2=val2;
  • --target (alias -t) - the target environment in which to deploy the services. If not specified, default target will be used, mentioned in sasjsconfig.json. The target can exist either in the local project configuration or in the global .sasjsrc file.

  • --compile (alias -c) - optional argument that is used to compile the program prior to execution. Useful for including dependent macros and includes. More info here.

Using Github Urls

If using a URL from github, be sure to link to the raw version of the file, eg:

As opposed to:

If you click the links above you will see the difference. Whenever <sourcecode> begins with http:// or https:// we simply fetch the contents from the URL - so the raw value should be SAS code and nothing else.

You can find the raw version by clicking on the 'raw' button when viewing the program on github (next to the 'blame' button)


Running some local SAS code:

# create minimal SAS program
cat > ./ <<'EOL'
  %put hello from SASjs;

# run the SAS code on the target
sasjs run -t myTarget

Running some SAS code from github:

sasjs run -t viya


We plan to support the following:

  • keeping sessions alive
  • extracting items from the session

If there are items you are looking for, or have problems / ideas, do raise an issue.