|
Macros for SAS Application Developers
https://github.com/sasjs/core |
Writes JSON in SASjs format to a fileref. More...
Go to the source code of this file.
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.
Usage:
filename tmp temp; data class; set sashelp.class;run; %mp_jsonout(OPEN,jref=tmp) %mp_jsonout(OBJ,class,jref=tmp) %mp_jsonout(OBJ,class,dslabel=class2,jref=tmp,showmeta=Y) %mp_jsonout(CLOSE,jref=tmp) data _null_; infile tmp; input;putlog _infile_; run;
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 https://sasjs.io
| [in] | action | Valid values:
|
| [in] | ds | The 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:
|
| [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 |
Definition in file mp_jsonout.sas.