BookmarkSubscribeRSS Feed

Using SAS 'proc json' statement to export a JSON file for use with SAS Event Stream Processing

Started ‎03-28-2017 by
Modified ‎02-16-2018 by
Views 3,002

Question

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?

Answer

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.

Version history
Last update:
‎02-16-2018 05:19 PM
Updated by:

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags