Login  Register

Re: delete specific value label

Posted by emma78 on May 20, 2021; 7:20am
URL: http://spssx-discussion.165.s1.nabble.com/delete-specific-value-label-tp5740529p5740535.html

Hi Jon,
you're right when i did it manually it is working with the comma
But when  I use this

/begin program.
import spss, spssaux
import re

vardict = spssaux.VariableDict()
selected = []
for v in vardict:
    keys = v.ValueLabels.keys()
    values = v.ValueLabels.values()
    if keys:
        keymatch = [re.search(r"3", key, re.I) for key in keys]
        valuematch = [re.search(r"weiß+", value, re.I) for value in values]
        both = zip(keymatch, valuematch)
        test = [key is not None and val is not None for (key,val) in both]
        if any(test):
            selected.append(v.VariableName)
print selected
spss.SetMacroValue("!selectedvars36", "\n".join(selected))
end program.

begin program.
variables = '!selectedvars36' # Specify variables here.
value = 1 # 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./

i got an error message:

Traceback (most recent call last):
  File "<string>", line 6, in <module>
  File
"C:\PROGRA~1\IBM\SPSS\STATIS~1\24\PYTHON\Lib\site-packages\spssaux\spssaux.py",
line 1249, in expand
    raise ValueError, _msg19 + v
ValueError: Invalid variable or TO usage: !selectedvars36



--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD