Login  Register

Re: delete specific value label

Posted by Jon Peck on May 19, 2021; 5:14pm
URL: http://spssx-discussion.165.s1.nabble.com/delete-specific-value-label-tp5740529p5740532.html

When you set the value labels as in the last line of the code above, it actually generates a VALUE LABELS command that sets all the labels according to the dictionary.  I ran a similar command with and without a comma -  no problem.  If you can send an example that fails, I'll take a look.

The Dataset class modifies labels without generating syntax, but that api wasn't available when I wrote the spssaux module.

On Wed, May 19, 2021 at 7:39 AM emma78 <[hidden email]> wrote:
Hi ,
is it possible to delete a specific value label for some variables which i
put together in a macro?
I tried this but the variables need a  'to' between them, and in a macro
they are separated with a comma.



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.


Thank you!



--
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


--
Jon K Peck
[hidden email]

===================== 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