4

I need to change all the value labels of all my variables in my spss file to be the value itself.

I first tried - Value Labels ALL. EXECUTE.

This removes the value labels, but also removes the value entirely. I need this to have a label of some sort as I am converting the file and when there is no values defined it turns the value into a numeric. Therefore, I need the all value labels changed into numbers so that each value's label is just the value - value = 1 then label = 1.

Any ideas to do this across all my variables??

Thanks in advance!!

Joshua
  • 40,822
  • 8
  • 72
  • 132
PTrem1
  • 109
  • 5
  • Possible using python but I can't see under what circumstance this would be at all beneficial? If you would like to elaborate at first if this is indeed what you want to do? – Jignesh Sutar Sep 05 '16 at 14:52
  • 1
    I'm converting my .SAV file into MDD/DDF format. The element identifier was coming out with the full text as the name (a bit unwieldy) so I want the element names to be 1 to whatever. Removing the value in SPSS causes the variable type to change to a numeric as opposed to a categorical after I convert the file. So, I think the best way around this for all my variables is to change the value label to the actual value – PTrem1 Sep 05 '16 at 16:10
  • I don't know much/anything about the file formats you mention (MDD/DDF) however have you tried changing `VARIABLE LEVEL` assignements from `SCALE` to `NOMINAL`. It would be much easier to do this for all necessary variables than set value labels for all variables/values. – Jignesh Sutar Sep 05 '16 at 16:55
  • 1
    Yes, that didn't seem to make any difference once all the values had been removed unfortunately. The variable actually stays as nominal when all the values are removed. Sounds like there's not an easy way to change all value labels! – PTrem1 Sep 06 '16 at 08:38
  • Easy enough to do if using python... – Jignesh Sutar Sep 06 '16 at 09:00
  • Maybe there's something shorter through PYTHON, but this can be automated with syntax only: capture all values of all variables with an appropriate OMS command and 'freq all.'. Then create a command in each line to add the value as a label, write out to a syntax file and insert it. – eli-k Sep 06 '16 at 10:33

1 Answers1

2

Here is a solution to get you started:

get file="C:\Program Files\IBM\SPSS\Statistics\23\Samples\English\Employee data.sav".
begin program.
import spss, spssaux, spssdata
spss.Submit("set mprint on.")
vd=spssaux.VariableDict(variableType ="numeric")
for v in vd:
    allvalues = list(set(item[0] for item in spssdata.Spssdata(v.VariableName, names=False).fetchall()))
    if allvalues:
        cmd="value labels " + v.VariableName + "\n".join(["  %(i)s '%(i)s'" %locals() for i in allvalues if i <> None]) + "."
        spss.Submit(cmd)
spss.Submit("set mprint off.")
end program.

You may want to read this to understand the behaviour of fetchall in reading date variables (or simply exclude date variables from having their values labelled also, if they cause no problems?)

Jignesh Sutar
  • 2,909
  • 10
  • 13