Getting Value labels

Jun 27, 2011 at 7:25 AM
Edited Jun 27, 2011 at 8:39 AM

Hi,

Is dataset.Variables[0].ValueLabels, the correct way to get the value labels?

var stream = File.OpenRead("C:\101124 1036.sav" ); 
var dataset = new SavFileLibrary.SpssDataset.SpssDataset (stream);

currently the values dataset.Variables[0].ValueLabels returned are not correct.

For eg. If there are 3 variables A,B,C with 2,3,4 value labels,

dataset.Variables[0].ValueLabels will return 0,

dataset.Variables[1].ValueLabels will return 2 and dataset.Variables[2].ValueLabels will return 3

Regards

Mathew

 

 
Jun 24, 2013 at 10:03 AM
Edited Jun 24, 2013 at 10:05 AM
Hello, for a strange reason, SPSS sav value is stored as a double (double precision float, ex: 1 is stored as 1.0 in binary).
Therefore, you should use a BitConverter.ToDouble to read properly the valueLabel key:
                for (int i = 0; i < dataset.Variables.Count; i++)
                {
                    Console.WriteLine(dataset.Variables[i].Name + "=" + dataset.Variables[i].Label + ":" + dataset.Variables[i].MeasurementType);
                    if (dataset.Variables[i].MeasurementType == SavFileLibrary.SpssDataset.MeasurementType.Scale)
                        foreach (byte[] j in dataset.Variables[i].ValueLabels.Keys)
                            Console.WriteLine(BitConverter.ToDouble(j,0) + " = " + dataset.Variables[i].ValueLabels[j]);
                }
Stylo.