myronliu347 / sav-writer Goto Github PK
View Code? Open in Web Editor NEWwrite spss file(.sav)
write spss file(.sav)
Hello! First I want to thank you for sharing the project with the community.
I need to generate (export data in sav format) a SAV data file for SPSS and I found your project on github, but I don't know how to use your lib. I couldn't find documentation or examples.
Could you post an example file (may be a small thing) of how to generate a SAV file using your lib? It will be of great help to me.
Thanks!
I'm passing a correct width (451 for example) and the reader cuts the string WHEN READING BACK (with sav-reader library), and when opening with pspp there is an error message:
error: '/Users/hfabio/test-spss/write.sav' near offset 0x6bc: Incorrect length 451 for the variable XX
I guess that its a bug when relating the variables and records, one can be pointing the correct data length in bytes and the other is just misaligned, but I couldn't figure out the problem properly....
to test, try this:
const {SavFileReader} = require('sav-reader');
const {saveToFile} = require('sav-writer');
const main = async () => {
const records = [
{XX: 'this is a short string, we should be good'},
{XX: 'this is a medium string, lets keep the eyes opened on this problem'},
{XX: "this is a limit string, it shouldn't raise the problem described because it has 255 characters bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla b bla bla bla bla bla bla bla bla bla bla bla bla bla bla bl"},
// if you enable this line it breaks:
// {XX: 'this is the problem string it should raise the problem described because it has 451 characters bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla cuts here -> bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla b bla bla bla bla bla bla bla bla bla bla b'}
]
const variables = [
{name: 'XX', label: 'X variable', columns: 8, decimal: 0, type: 1, width: 255}
// enable this one down below and comment above to take the right width
// {name: 'XX', label: 'X variable', columns: 8, decimal: 0, type: 1, width: 451}
]
saveToFile('test-long-string.sav', records, variables);
const written = await read('test-long-string.sav');
const sav = new SavFileReader(filePath);
await sav.open();
const rows = await sav.readAllRows();
const breakpoint = true; // break point here and compare what was read.
}
main()
I'm using macOS and node v18.15.0 by the way.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.