Skip to content

sasjs create

To create a new project, run: sasjs create mynewproject

To install in an existing project, change into that directory and run: sasjs create (without arguments). This will create a sas folder inside the directory.


From the root of the project, run: sasjs compile. This will take all of the macros in the services folder and create equivalents in the sasbuild folder. Each service will contain all of the dependent macros as listed under dependencies in the header, as well as the and files. sasjscliflow.png

If streamWeb is true then the index.html file in your webSourcePath is scanned and any linked JS / CSS files are also compiled into the streamWebFolder folder. The index.html becomes a clickme service in your appLoc SAS folder root.

Base64 encoding

If you don't have an index.html and you just want to compile arbitrary binary content (such as images, mp3, excel files etc) as base64 services, set the location of the content in assetPaths. All files in the specified folder(s) will be turned into web services.


From the root of the project, run: sasjs build. This will create a deployment script that can be executed in SAS to create the backend services. The appLoc is configured in the /sas/config.json file, along with the serverType (SAS9 or SASVIYA). A program can be configured to run, along with specific macro variables (tgtBuildVars), according to the settings in sasjsconfig.json.

If you have sensitive build variables (such as an access_token) you can set these in a .env file in your project root.

If the services folder does not exist in the sasjsbuild folder, then the sasjs compile step is also executed. The alias to run both compile and build steps is sasjs cb. sasjscliflow.png

Viya Build Script

The Viya build script requires a number of variables to be prepared by an administrator. Execute the following:

filename mc url "";
%inc mc;
%let client=MyClient;
%let secret=MySecret;
This will generate a URL in the log, which must be followed to generate a refresh code (one time step):


The ACCESS_TOKEN and REFRESH_TOKEN are now in the log. In future, when running sasjs build for a Viya target, the following values must be provided:

%let client=MyClient;
%let secret=MySecret;
/* these values are long - split over multiple lines with %trim()*/
%let ACCESS_TOKEN=MyGeneratedAccessToken;
%let REFRESH_TOKEN=MyGeneratedRefreshToken;

The above can then be securely placed in a read-protected directory (such as a home directory on the SAS server) and %inc'd.


Saving security tokens in project repositories, especially if they are committed to source control, is a security risk - as anyone with access can use them to make modifications on the Viya platform. Be sure to use a secure mechanism such as the %inc approach described above, or another approved mechanism for securing these kinds of variables.


The build program generated in the previous step can be deployed in 3 ways:

1 - MANUAL: copy paste the code into SAS Studio or Enterprise Guide and run it

2 - SSH: build a shell script or bat file to load, and execute with a web service

3 - API: Use the SAS APIs

Points 2 and 3 can be configured / executed with a single sasjs deploy or sasjs d command. You can compile, build AND deploy using sasjs cbd [target]. If you don't specify a target (eg sas9 or viya) then the first target in the sasjsconfig.json file is used.

CopyPaste approach

The build script (named as per buildOutputFileName) can be copy pasted into SAS Studio and executed to create the backend services. Please note:

  • You will be running under your own identity. If you need files created under the Web Server identity, deploy your build script using a web service.
  • For Viya, you must use SASStudioV (or ensure the client/secret/access_token are provided)

SSH approach

You can SSH (rsync or scp) your build script onto the SAS Server then %inc it from a web service - the web service could be created using the code below:

filename mc url "";
%inc mc;
filename ft15f001 temp;
  %inc "/path/to/your/"/source2;
%mp_createwebservice(name=Executor, code=ft15f001 ,replace=YES)
This creates the service in your HOME directory (SAS 9 or Viya).

You can now create a local script (eg and add it to the tgtDeployScripts array (the root is always the sasjs folder).

echo "sasjs: uploading frontend"
rsync -avz /home/me/myapp/dist/* me@sasserver:/var/www/html/myapp

echo "sasjs: uploading deploy program"
scp sasjsbuild/ me@sasserver:/tmp/

echo "sasjs: running Executor"
curl -v -L -k  -b cookiefile -c cookiefile "$URL&$CREDS"

API Approach

Any files in your tgtDeployScripts array that have a ".sas" extension will be sent to the relevant API (9 or Viya) for execution.

Viya API deployment

The Viya deploy requires 3 things:

  • access_token
  • serverUrl
  • contextName

In order of priority, the access_token is taken from the following locations:

  • tgtDeployVars
  • tgtBuildVars
  • the .env file. This is the preferred / recommended location!

The serverUrl is the location of your Viya server. The contextName is the execution service on which your SAS code will execute. You can get a list of available contexts by running a GET to the following endpoint: /compute/contexts


For SAS 9 deployment we integrate with SAS9API by Analytium (, you can contact them for a free trial copy.

Configuration as follows:

  "tgtDeployVars": {
      "serverName": "SASApp",
      "repositoryName": "Foundation"
  "serverUrl": "https://SASSERVER:PORT",


A 2 minute video demonstrating how an app can be built and a deployment script created is shown below.