SPSS Tutorials

BASICS REGRESSION T-TEST ANOVA CORRELATION

Strip Prefix from Variable Labels

Question

“My variable labels all have prefixes that end with ": ". How can I remove those in order to prettify these labels?”

SPSS Python Syntax Example

begin program.
variables = 'all' # Specify variables here.
delim = ': ' # Specify delimiter here.
import spss,spssaux
sdict = spssaux.VariableDict(caseless=True)
for var in sdict.expand(variables):
    varLab = sdict[sdict.VariableIndex(var)].VariableLabel
    varLab = varLab[varLab.find(delim) + len(delim):] if varLab.find(delim) != -1 else varLab
    sdict[var].VariableLabel = varLab
end program.

Description

Previous tutorial: Suffix All Variable Names

Next tutorial: Select Variables by Variable Labels

Let me know what you think!

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

This tutorial has 4 comments