Analyzer for SAS
Static analysis for SAS programs and their macros, across a whole project,
without running any code. It adds go-to-definition, find-references, hover
and diagnostics to the SAS support you already have.
SAS and all other SAS Institute Inc. product or service names are registered
trademarks or trademarks of SAS Institute Inc. This project is not affiliated
with or endorsed by SAS Institute Inc.
It works beside the official SAS extension
Install the official
SAS extension (SAS.sas-lsp)
first. It owns the SAS language in VS Code: highlighting, completion,
snippets, and running code. This extension contributes no language, no
grammar and no highlighting of its own, so without the official extension a
.sas file opens as plain text and nothing here starts.
What this extension adds is what a reader of the code can answer without a
SAS session:
- Go to definition and find references for macros, across files: a
%macro defined in another file is found when the caller can reach it,
through an %include that runs before the call or through an autocall
folder you configure.
- Data sets, too. Hover, go to definition and find references work on a
data set name in a DATA step, in PROC SQL, in a procedure's
data=,
out= and base=, and inside a macro body for the values each call
passes. Hover says which library the name is in, what this step does to
the table, where it was last written, and lists its columns with their
type, format and length.
- Programs, not just files. Many projects split a program over files
that only make sense where an
%include brings them in. Such a file is
read inside the program that includes it, with the libraries, macro
variables and macros set before that point, and an %include in the
middle of a DATA step is read as part of that step. That also holds for
an %include inside a macro, read for each call that runs it, so a
project that includes its files through a macro of its own works too,
and for one whose path is built from macro variables, once the path is
known. Name your programs' start files in project.programRoots, and a
file that is only ever included is checked only there.
- Hover on a macro call shows what that call expands to, with the
values that are not known marked, and where the macro was defined and how
this file reaches it. On a DATA step variable it says the variable's type
and where its value came from. In open files hovers are worked out in the
background, so they answer at once.
- Diagnostics without running SAS: unclosed
%do, do and select
blocks, statements where SAS rejects them, a macro that generates a whole
step where only a value fits, a macro SAS would not compile or would stop
partway, an %include that SAS refuses or that cannot be found, macros
that no reachable file defines, and a few checks on DATA step variables.
A macro call whose generated text completes the statement around it is
not reported as a syntax error. Errors and warnings also appear for files
you have not opened, worked out in the background. Each code has its own dropdown under Settings → Extensions → Analyzer
for SAS → Lints, where its severity can be changed or the code turned off; parse
errors are the only findings no setting grades.
- Code lenses: "N references" above every
%macro, "read by N" above
every table a step writes, and on an included file, which file includes
it and how it is read there.
- Outline, folding and selection ranges for SAS files. Both extensions
fold SAS files, and VS Code merges the two. To use only one extension's
folds (VS Code 1.73 or later), set
"[sas]": { "editor.defaultFoldingRangeProvider": "htrojan.analyzer-for-sas" },
or put SAS.sas-lsp in place of this extension's id. The Outline shows one
group for each extension.
Macros are read, not run, the way SAS's macro processor reads them,
quoting functions and comments included. A macro whose arguments are known
at the call is followed through for that call: its %if decided where
those arguments decide it, and its %do loops unrolled where their bounds
are known.
Values that only the SAS session knows, such as a macro variable an
autoexec sets or a library a job assigns, can be supplied in the settings.
Settings worth knowing
All settings are under sas-analyzer. in the Settings editor. The ones that
make the biggest difference on a real project:
project.programRoots: the files your programs start at, so an
included file is read inside the programs that include it.
autocall.roots: the folders your SAS session searches for autocall
macros. autocall.memberNames also accepts z/OS member names, where #
stands for _.
include.workingDirectory: the SAS session's working directory, where a
relative %include path is looked for first.
include.searchPaths, include.filerefs and include.rewrites: where
else %include paths are found, including a deployment path that differs
from your checkout.
macroVariables: macro variables the session sets before your programs
run. A %let in the program takes precedence, as in SAS.
data.librefs: what a library name points to, where the program does not
say.
run.order: the order your programs run in, so a table one program
writes is found when the next one reads it.
lints.<code>: the severity of each diagnostic code, or off, one
dropdown per code in the Lints section.
memory.budgetMB: how much memory the server may keep on a large
project, about 3 GB by default, 0 for no limit.
diagnostics.closedFiles: whether files that are not open show their
errors and warnings.
Windows (x64), macOS (Apple silicon and Intel) and Linux (x64 and arm64).
VS Code installs the package built for your platform. On Windows the server
needs no Visual C++ Redistributable.
Privacy
Nothing is executed: no SAS code and no other program from your project.
Everything happens on your machine, offline. The extension sends nothing
anywhere.
| |