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:
[[event_block_n],[event_block_n+1],[event_block_n+2],...].
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;
export sashelp.class;
write close;
write close;
run;
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.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.