How do I use the SAS 'proc json' statement to export a data set to a JSON file that SAS Event Stream Process can interpret?
Exporting a SAS data set as a JSON file is possible with the 'proc json' statement. However, to interpret the newly created JSON file, SAS Event Stream Processing requires that it conform to the following specific format:
In the above template, the outermost brackets define an array of event blocks. Each nested pair of brackets defines an array of events that corresponds to an event block. Below is a sample ‘proc json’ step to create the format described above:
proc json out="C:\temp\sashelp_class.json" trimblanks nosastags;
write open array;
write open array;
By default, ‘proc json’ does not add the additional brackets that SAS Event Stream Processing requires. To ensure SAS Event Stream Processing can interpret your JSON file, you can add the additional brackets using two ‘write open array’ statements to begin the ‘proc json’ step followed by two ‘write close’ statements at the end of the ‘proc json step’.
Also by default, the ‘proc json’ statement will add some metadata information about the data set at the top of the file, as well as enclose the entire contents of the file in curly braces. Specifically, this metadata consists of the SAS export version, exported SAS data set name, and any non-default option specification. Using the option 'nosastags' will ensure that the metadata is not appended to the beginning of the file and the curly braces are omitted.
Finally, ‘proc json’ will append a new line to the end of the outputted JSON file. Sometimes, ESP will not accept this additional empty line and will reject the JSON file. To account for this, use the ‘trimblanks’ option, which removes trailing blanks from the end of character data in the JSON output.
Also see attached file of a working SAS Event Stream Processing XML model. The model will be importing the JSON file created based on the Class dataset (from the sashelp library) that is included with every SAS install.