SAS Packages (SPF)
<!-- SPDX-License-Identifier: MIT -->
A
SAS package is a single zip holding a group of SAS programs (macros, functions, data steps) plus automatically generated description, load, unload and help files. The
SAS Packages Framework (SPF, by Bartosz Jablonski) installs and loads them from a folder of zips, so a package can be pinned, versioned and swapped without touching
or a macro catalogue.
This skill covers using the framework as a consumer. It is not SASjs-specific - SPF is an independent project, and the packages it serves come from any author.
When to use
- Installing a package into a SAS session, e.g. (the SASPAC packaging of @sasjs/core)
- Debugging / / failures
- Setting up a packages folder, or working out which path to point the fileref at
- Loading macros for one job without adding them to a shared server's
Don't use for: authoring or publishing a package (
), or for @sasjs/core's own macro coding standards - see the
skill for those.
Enabling the framework
The framework is a single file. Enable it in the session:
sas
filename packages "%sysfunc(pathname(work))";
filename SPFinit url "https://bit.ly/SPFinit";
%include SPFinit;
The raw URL
https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/main/SPF/SPFinit.sas
is the same file without the shortener, and is a better choice where a redirect is unwanted. Enabling the framework needs internet access from the SAS session; it is a one-off per session unless the file is kept on disk (see Persistence below).
The packages fileref (mandatory)
- The fileref must be named . and are reserved keywords in SPF; a different name is not picked up.
- It points at a directory, not a zip file.
- The directory must already exist. SPF does not create it - is documented as equivalent to manually downloading the zip into that folder, and it will not make the folder for you.
Pick the path by what you need:
| Need | Use |
|---|
| Throwaway / portable, works on Windows, Viya and SASjs Server | filename packages "%sysfunc(pathname(work))";
|
| Survives the session (install once, reuse) | A real directory that exists, e.g. on Windows, or any writable directory on a Linux estate |
appears throughout the SPF documentation, but it is a Windows example. On Linux (Viya, SASjs Server) it is just a relative path, so unless that directory happens to exist the install fails - see Pitfalls.
Install, load, unload
sas
%installPackage(sasjscore) %* download the zip into the packages folder;
%helpPackage(sasjscore) %* print the package description and contents;
%loadPackage(sasjscore) %* compile the macros into the session;
%unloadPackage(sasjscore) %* remove them again;
- fetches the zip over the network. Default source is the SASPAC archive,
https://github.com/SASPAC/
; override with or .
- Package names are space separated and carry no extension:
%installPackage(pkg1 pkg2)
. Pin a version in parentheses: %installPackage(baseplus(1.17) macroarray(1.0))
. Add to refuse to overwrite an already-installed package.
- installs the framework itself into the packages folder.
- compiles into the session; deletes those entries from the macro catalogue. A job that needs the macros but whose server should not carry them in can load, use and unload in one session.
- Where the SAS session has no zip fileref support, unzip into and pass :
%loadPackage(pkgname,zip=disk,options=)
.
Persistence: install once, then go offline
Install the framework into the packages folder once:
After that the two network-facing lines collapse to a local include, and no network access is needed at run time:
sas
filename packages "/permanent/path/to/packages";
%include packages(SPFinit.sas);
%loadPackage(sasjscore)
This requires the fileref to point at a permanent directory - with
the framework is gone when the session ends.
Pitfalls
- is a failure, despite reading as success. prints
Done with return code rc=20006 (zero = success)
- the parenthetical is just the message template. 20006 means the install failed; the real error is the ERROR: Physical file does not exist, <dir>/<name>.zip
line that follows. Do not trust the line alone.
- The packages folder must exist before you call . This is the most common cause of the failure above, and it bites hardest on Linux because the documented example silently becomes a relative path. Verify with
%put %sysfunc(fileexist(<dir>));
and create it first if it returns 0.
- A missing zip cascades. Once the install fails, and both fail with
File "<dir>/<name>.zip" does not exist!
, and the macros are simply absent - a later call gives WARNING: Apparent invocation of macro X not resolved
. Fix the install rather than chasing the macro.
- Installing needs network egress from the SAS session, not from your workstation. A locked-down compute context without internet cannot reach SASPAC or GitHub.
- is per session. Macros loaded in one session are not visible in another; re-load in each session (or use / the CLI for durable resolution).
Verification
After loading, prove the macros are actually live rather than assuming the install worked:
sas
%put NOTE: package version check;
%helpPackage(sasjscore) %* prints "Help for package SASjsCore, version X.Y.Z, license MIT";
%put NOTE: getuser returns %mf_getuser();
A clean run shows
INFO: Package sasjscore installed.
, the help block with an explicit version, and a resolved macro call.
can then be confirmed by the same call returning
Apparent invocation of macro MF_GETUSER not resolved
.
Limitations
This skill is a static reference for the SAS Packages Framework. It does not execute SAS code, run shell commands, access the filesystem, or make network requests. Code examples are illustrative and must be submitted to a SAS session by the user. The framework is maintained at
https://github.com/yabwon/SAS_PACKAGES and the archive at
https://github.com/SASPAC - consult those for the authoritative macro reference and the current framework version.