Warm tip: This article is reproduced from serverfault.com, please click

NodeJS reading and producing SAS files: xport and sas7bdat

发布于 2016-02-29 15:19:51

I have been looking around for a way to digest and export SAS files using NodeJS. I guess it can be done by means of:

  1. C++ extension to NodeJS
  2. Some sort of JavaScript framework

I couldn't find anything ready made on the Internet. I haven't tried to cook one up myself. I am not considering other options such as to get SAS to export CSVs. I assume that SAS is not available to NodeJS.

Does anyone know of any ready made way of making NodeJS to work with xport and sas7bdat files?

Regards, Vasilij

Questioner
Vasilij Nevlev
Viewed
0
dumbmatter 2016-05-15 06:21:04

I just made this for sas7bdat files: https://github.com/dumbmatter/sas7bdat-js

It's a pure JS module for reading sas7bdat files in NodeJS. Install with:

npm install sas7bdat

Then load the module:

const SAS7BDAT = require('sas7bdat');

SAS7BDAT.createReadStream returns a stream that emits individual rows, one at a time:

const stream = SAS7BDAT.createReadStream('test.sas7bdat');
stream.on('data', row => console.log(row));
stream.on('end', () => console.log('Done!'));
stream.on('error', err => console.log(err));

SAS7BDAT.parse returns a promise that resolves to an array containing all the rows:

SAS7BDAT.parse('test.sas7bdat')
    .then(rows => console.log(rows))
    .catch(err => console.log(err));