Remove Value Label from Multiple Variables

Question

“I’d like to completely remove the value label from a value for many variables at once. Is there an easy way to accomplish that?”

SPSS Python Syntax Example

begin program.
variables = ‘v1 to v5‘ # Specify variables here.
value = 3 # Specify value to unlabel here.
import spss,spssaux
vDict = spssaux.VariableDict(caseless = True)
varList = vDict.expand(variables)
for var in varList:
valLabs = vDict[vDict.VariableIndex(var)].ValueLabels
if str(value) in valLabs:
del valLabs[str(value)]
vDict[vDict.VariableIndex(var)].ValueLabels = valLabs
end program.

Description

  • Since this syntax uses Python, make sure you have the SPSS Python Essentials installed.
  • The two things you’ll want to modify for using the example on other data are the variables and the value from which the label should be removed. Both are boldfaced in the syntax example.
  • Note that the variables can be specified using the TO and ALL keywords.
  • One could use supermarket.sav for testing purposes.

Post Author: Zahid Farid