SPSS Tutorials

BASICS REGRESSION T-TEST CHI-SQUARE TEST ANOVA

Prefix Many Value Labels

Question

"In my data, many values are answers to questions. In order to make this clear, I'd like to prefix their value labels with "Answer: ". For now, I want to apply this only to the fifth through the fourteenth variable in my data."

SPSS Python Syntax Example

*1. Prefix many or all value labels.

begin program.
variables = 'v5 to v14' #Please specify variables whose value labels should be prefixed.
pref = 'Answer: ' #Please specify prefix.
import spss,spssaux
sdict = spssaux.VariableDict()
for var in sdict.expand(variables):
    vallabs = sdict[sdict.VariableIndex(var)].ValueLabels
    for val,lab in vallabs.iteritems():
        vallabs[val] = pref + lab
    sdict[var].ValueLabels=vallabs
end program.

Description

Previous tutorial: Select Variables by Variable Labels

Next tutorial: Sort Values within Cases

Let me know what you think!

*Required field. Your comment will show up after approval from a moderator.