Macros for SAS Application Developers File Reference

Writes JSON in SASjs format to a fileref. More...

Go to the source code of this file.

Detailed Description

This macro can be used to OPEN a JSON stream and send one or more tables as arrays of rows, where each row can be an object or a nested array.

There are two engines available - DATASTEP or PROCJSON.

PROC JSON is fast but will produce errs like the ones below if special chars are encountered.

‍(ERR)OR: Some code points did not transcode.

‍An object or array close is not valid at this point in the JSON text.

‍Date value out of range

If this happens, try running with ENGINE=DATASTEP.

The DATASTEP engine is used to handle special SAS missing numerics, and can also convert entire datasets to formatted values. Output JSON is always in UTF-8.


  filename tmp temp;
  data class; set sashelp.class;run;


  data _null_;
  infile tmp;
  input;putlog _infile_;

If you are building web apps with SAS then you are strongly encouraged to use the mX_createwebservice macros in combination with the sasjs adapter. For more information see

[in]actionValid values:
  • OPEN - opens the JSON
  • OBJ - sends a table with each row as an object
  • ARR - sends a table with each row in an array
  • CLOSE - closes the JSON
[in]dsThe dataset to send. Must be a work table.
[out]jref=(_webout) The fileref to which to send the JSON
[out]dslabel=The name to give the table in the exported JSON
[in]fmt=(Y) Whether to keep (Y) or strip (N) formats from the table
[in]engine=(DATASTEP) Which engine to use to send the JSON. Options:
  • PROCJSON (default)
  • DATASTEP (more reliable when data has non standard characters)
[in]missing=(NULL) Special numeric missing values can be sent as NULL (eg null) or as STRING values (eg ".a" or ".b")
[in]showmeta=(N) Set to Y to output metadata alongside each table, such as the column formats and types. The metadata is contained inside an object with the same name as the table but prefixed with a dollar sign - ie, ,"$tablename":{"formats":{"col1":"$CHAR1"},"types":{"COL1":"C"}}
[in]maxobs=(MAX) Provide an integer to limit the number of input rows that should be converted to JSON

Related Files

Allan Bowe @source

Definition in file