SPSS .NET库

3
我正在使用Spss .net库http://spss.codeplex.com创建.sav文件,但是我似乎找不到如何创建cases。我正在使用C#。
请问有人可以指点我正确的方向吗?
2个回答

4
为了避免使用本地的spssio32/64并且不必处理SPSS的32位和64位问题,我们已经创建了一个DLL的本地实现。它基于SPSS/PSPP规范工作,并且是您之前提到的SpssLib的延续。
将记录写入的示例如下:
// Create Variable list
var variables = new List<Variable>
{
    new Variable
    {
        Label = "The variable Label",
        ValueLabels = new Dictionary<double, string>
                {
                    {1, "Label for 1"},
                    {2, "Label for 2"},
                },
        Name = "avariablename_01",
        PrintFormat = new OutputFormat(FormatType.F, 8, 2),
        WriteFormat = new OutputFormat(FormatType.F, 8, 2),
        Type = DataType.Numeric,
        Width = 10,
        MissingValueType = MissingValueType.NoMissingValues
    },
    new Variable
    {
        Label = "Another variable",
        ValueLabels = new Dictionary<double, string>
                    {
                        {1, "this is 1"},
                        {2, "this is 2"},
                    },
        Name = "avariablename_02",
        PrintFormat = new OutputFormat(FormatType.F, 8, 2),
        WriteFormat = new OutputFormat(FormatType.F, 8, 2),
        Type = DataType.Numeric,
        Width = 10,
        MissingValueType = MissingValueType.OneDiscreteMissingValue
    }
};
// Set the one special missing value
variables[1].MissingValues[0] = 999;  

// Default options
var options = new SpssOptions();

using (FileStream fileStream = new FileStream("data.sav", FileMode.Create, FileAccess.Write))
{
    using (var writer = new SpssWriter(fileStream, variables, options))
    {
        // Create and write records
        var newRecord = writer.CreateRecord();
        newRecord[0] = 15d;
        newRecord[1] = 15.5d;
        writer.WriteRecord(newRecord);

        newRecord = writer.CreateRecord();
        newRecord[0] = null;
        newRecord[1] = 200d;
        writer.WriteRecord(newRecord);
        writer.EndFile();
    }
}

GitHub上查找源代码,并在NuGet上获取二进制文件。

0

merthsoft在以下stackoverflow帖子中的回答为使spss运行提供了一个良好的起点。 在C#中使用64位SPSS库

我个人遇到的问题是包括所有适当的dll,如... spssio64.dll icudt32.dll icuin32.dll icuuc32.dll

在导出数据时,所有列都需要是唯一的。

如果您按照merthsoft的类似模式进行操作,则创建案例的可能解决方案可能是封装和公开此方法...

[DllImport("spssio64.dll", EntryPoint = "spssCommitCaseRecord"...

我希望现在你已经让它工作了,但对于将来遇到这个问题的人们,这可能有所帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接