SAS open-source treasures from around the world: SASjs


Editor’s note: SASjs, while free and useful for anyone, is a gateway to services from 4GL Apps, a company founded and operated by longtime SAS user Allan Bowe.Open code sharing

I would like to start this post with a well-known quote by George Bernard Shaw: “If you have an apple and I have an apple and we exchange these apples then you and I will still each have one apple. But if you have an idea and I have an idea and we exchange these ideas, then each of us will have two ideas.”

SAS Software provides vast functionality delivered with it, but perhaps the biggest asset of the SAS ecosystem is its ever-growing community of SAS users around the globe readily willing to share their SAS code and solutions to various problems. Take for example, SAS Communities, SAS blog or SAS Software on GitHub.

With open-source code taking the world by storm, SAS maintains and nurtures a viable mix of its rock-solid backbone – commercial SAS Software backed by its unparalleled Technical Support and open-source SAS solutions developed and shared by SAS users.

An introduction to SASjs

Here, I am going to introduce you to one more publicly available open source treasure called SASjs (also available on GitHub), which stands out from many others because of its thought-provoking, multifaceted approach.

In a nutshell, the SASjs is a collection of tools aimed at enabling and accelerating development and operations (DevOps) for a broad range of SAS applications, including SAS web development.

SASjs consists of the following three major components:

  1. SAS macro library (MacroCore)
  2. JavaScript library (Adapter)
  3. Command line interface (CLI)

SASjs MacroCore library

The MacroCore library is a centerpiece of the SASjs framework. It includes several hundred SAS macros facilitating various aspects of SAS coding, application development and deployments. All these macros are production quality and free to use (MIT-licensed). The contents of the MacroCore library organized by the following sections:

  • BASE library (SAS9/Viya) - prefixes: mf (macro functions), mp (macro procedures - macros).
  • FCMP library (SAS9/Viya) - prefix: mcf; used to generate user-defined functions using PROC FCMP.
  • META library (SAS9 only) - prefix: mm; used in SAS EBI environments that connect to the metadata server.
  • SERVER library (@sasjs/server only) - prefix: ms; used for building applications using @sasjs/server - an open source REST API for Desktop SAS.
  • VIYA library (Viya only) - prefixes: mv, mvf; used for interfacing with SAS Viya.
  • METAX library (SAS9 only) - prefixes: mmw, mmu, mmx.
  • DDL Library - prefix: mddl; provides the structure for any permanent table used by the macros.
  • LUA library - prefix: ml

All these macros (except METAX) are Operating System independent and operate under NOXCMD option. That option prevents the SAS program from executing OS commands and is often implemented by SAS Administrators for security reasons.

DOCUMENTATION PAGE – here you can find detailed descriptions for all of the SASjs MacroCore macros.

DOWNLOAD PAGE – here you can grab all these macros FREE and deploy (save) anywhere in your SAS environment.

Alternatively, you can make all these macros available in your SAS program by %INCLUDE-ing them directly from the Web – just add this code snippet to the beginning of your SAS program:

filename mcore url "";
%inc mcore;

To give you a taste of what these macros are here is a small sample of them with examples of usage and brief descriptions:

  • %mp_copyfolder(&rootdir,&copydir) - copies the whole directory structure including files and subdirectories from one location (&rootdir) to another (&copydir). Uses only internal SAS functions without OS commands (NOXCMD option).
  • %mp_dirlist(path=/some/location, outds=myTable, maxdepth=MAX) - returns SAS table myTable listing all files and sub-directories up to specified depth. It also uses only internal SAS functions without OS commands (NOXCMD option).
  • %mp_csv2ds(inref=mycsv,outds=myds,baseds=template_ds) - imports relevant columns from mycsv CSV file to myds data table using a template dataset template_ds to provide the types and lengths.
  • %mf_getvarcount(my_dataset) - this macro function returns the number of variables in a dataset.
  • %mf_getvarlist(sashelp.class,dlm=%str(,),quote=double) - this macro function returns the dataset variable list directly from its header. The list can be separated by blanks, commas or any other delimiter (dlm=), and be unquoted or quoted (quote=).

SASjs Javascript library (Adapter)

In my earlier posts about integrating SAS with Google Maps, I employed and implemented the idea of using SAS for generating data-driven HTML and JavaScript code for creating web pages.

SASjs, on the other hand, turns on its head this SAS-to-JavaScript paradigm. In a total reverse, it uses JavaScript to generate SAS code for running on SAS servers as jobs or stored processes.

Previously, I naively believed that JavaScript is a web browser language that exists and used only within web browsers to enhance interactions with HTML web pages. SASjs proved me wrong. It turns out JavaScript is a general-purpose language that can be used everywhere outside of the web browser.

SASjs extensively employs this JavaScript functionality. Its second component, SASjs Adapter, is a server-side JavaScript library (and a set of SAS macros) to handle the communication between the frontend HTML5 or client application and the SAS 9 or Viya backend SAS services.

SASjs uses the following two client-side components:

  • Node.js JavaScript runtime environment.
  • Visual Studio Code (VS Code) source code editor.

Node.js is an asynchronous event-driven JavaScript runtime designed to build scalable network applications.

Visual Studio Code (VS Code) is a lightweight but powerful source code editor, which runs on your desktop and is available for Windows, macOS and Linux. It comes with built-in support for JavaScript, TypeScript and Node.js and has a rich collection of extensions for other languages (such as C++, C#, Java, Python, PHP, Go, etc.) and runtimes (such as .NET and Unity). In essence, it is more than just a source code editor, it is an Integrated Development Environment (IDE) allowing you to perform programming along with development as well as debugging and testing the application.

SASjs command line interface (CLI)

The SASjs CLI is the third major component of SASjs that ties together and facilitates creating, building, deploying and executing various SAS web applications (for SAS 9 and SAS Viya).

It is a powerful and flexible tool covering a wide range of features and functionalities to support successful applications development and operations (DevOps). CLI’s primary actions include:

  • Create a template SASjs Git project repository.
  • Compile dependent macros, macro variables and pre/post code.
  • Create/build the master SAS deployment, including Jobs, Services and Tests.
  • Deploy/execute local scripts and remote SAS programs to create your app on the SAS Server.
  • Configure and generate Doxygen documentation for all SAS content.

There is also a feature to let you deploy your frontend as a service, bypassing the need to access the SAS Web Server.

SASjs support

Even though SASjs is an open source platform, it provides different levels of support for its products.

Report defects. Through this GitHub web page SAS users can raise issues with SASjs such as report defects, suggest improvements, etc.

Engage with SASjs developers. SAS users can also communicate with SASjs developers, receive free clarifications and consultations on various aspects of SASjs usage, or even hire them for involvement that is more extensive.

Questions? Thoughts? Comments?

Do you find this post useful? Have you learned anything new? Do you have any other SAS open-source assets you can share? Do you have questions, concerns, comments? Please share with us below.


About Author

Leonid Batkhan

Leonid Batkhan is an independent SAS consultant and blogger. He holds a Ph.D. in Computer Science and Automatic Control Systems and has been a SAS user for more than 25 years. From 1995 to 2021 he worked as a Data Management and Business Intelligence consultant at SAS Institute. During his career, Leonid has successfully implemented dozens of SAS applications and projects in various industries. All posts by Leonid Batkhan >>>


  1. Wow, this is a very nice and useful blog, thanks so so much @Leonid. Actually I didn't know how to use the SASjs MacroCore library, had bookmarked it, but never had idea how to use it, Now I know where to look for Macros, that I can always improve or use in my programs.

  2. Thank you very much, Leonid, for one more treasure! The language is clear and text is very constructive and logical! I am always jealous when I see your articles - I wish I have a chance and time to learn all these tools! It is like getting into a LEGO store for a child with very limited money. People who overwhelmed with daily projects and endless routine in their jobs sometimes are just dreaming about the way to get into the space - open SAS space, that now has the name SASjs! You defined goals and described their structure, which means a start.
    I found very interesting macros in the MacroCore Library and definitely going to use some of them! JavaScript is on my plate too. Delicious!

Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Top