Skip to content

sasjs snippets

The sasjs snippets command generates VS Code snippets from any SAS macros contained in the folders (or subfolders) listed in the macroFolders array of the sasjs/sasjsconfig.json file. If macroFolders is defined at both configuration and target level, the two arrays will be merged in a single array of macro folders. Macros are those that fit the "$(macroname).sas" pattern - tests (such as macroname.test.sas or macroname.test.1.sas) are excluded, as are files with a non ".sas" extension.

Note - snippets are generated from the filename and doxygen header content, not the SAS code itself.

Syntax

sasjs snippets --outDirectory <folderPath> --target <targetName>
  • --outDirectory (alias -o) - optional output directory. If not present, the snippets will be saved to the sasjsresults/sasjs-macro-snippets.json file.
  • --target (alias -t) - optional SASjs target that should be used.

Generate Snippets File

Consider the file name my/macros/example.sas:

/**
  @file
  @brief An example macro
  @details prints an arbitrary message to the log

  @param msg The message to be printed
  @author Allan Bowe

**/

%macro example(msg);

  %let testvar=%sysfunc(ranuni(0));

  data work.example;
    msg=symget('msg');
    putlog msg=;
  run;

%mend example ;

Assuming a sasjs/sasjsconfig.json file as follows:

{
  "$schema": "https://cli.sasjs.io/sasjsconfig-schema.json",
  "macroFolders": [
    "my/macros"
  ]
}

Simply run the sasjs snippets command within the SASjs project, and the following file will be written to sasjsresults/sasjs-macro-snippets.json:

{
  "example": {
    "prefix": "%example",
    "body": "%example($1)",
    "description": [
      "An example macro",
      "\r",
      "Params:\r",
      "-msg The message to be printed\r"
    ]
  }
}

Notice that the doxygen @brief value has been placed at the beginning of the description, and @param has been put to the Params section. The file name has been used to populate the prefix and body of the VS Code snippet, and placeholders are also created in the body.

Import Snippets to VS Code

In order to import the generated VS Code snippets file please follow these steps:

  1. Open Command Pallet by pressing F1 (unix) or ctrl+shift+P (windows).
  2. Type Snippets: Configure User Snippets.
  3. Choose sas.json.
  4. Copy everything from the file generated by sasjs snippets command and paste it into sas.json.
  5. Save sas.json
  6. Snippets should be available in any .sas file by typing %<name of the snippet> (%example for the snippet from an example provided above).