Categorygithub.com/jamiever/go-spss
repositorypackage
1.0.4
Repository: https://github.com/jamiever/go-spss.git
Documentation: pkg.go.dev

# README

go-spss

Go library for generating SPSS files

Inspired by and based on https://github.com/j0ran/xml2sav

Install

go get -u github.com/jamiever/go-spss

Usage

  1. Open a file to write to
file, _ := os.OpenFile(filename, os.O_RDWR|os.O_CREATE, 0644)
  1. Create a new SpssWriter
spssWriter, _ := gospss.NewSpssWriter(file)
  1. Write all variables
spssWriter.AddVariable(&gospss.Variable{
    Name:    "VAR1",
    Type:    gospss.SpssTypeNumeric,
    Measure: gospss.SpssMeasureOrdinal,
    Decimal: int8(0),
    Width:   int16(10),
    Label:   "VARIABLE LABEL",
    Labels:  []gospss.Label{
        gospss.Label{
            Value: "1",
            Desc: "My Value Label",
        },
    },
})
  1. Write all values
values := make(map[string]string)

// Values must point to the right variable name
for _, variable := range variables {
    values[variable.Name] = "1"
}

w.AddValueRow(values)
  1. Call the Finish func
spssWriter.Finish()