SPSS Tutorials

BASICS REGRESSION T-TEST CHI-SQUARE TEST ANOVA

Suffix All Variable Names

Question

I have a data file in which all variables were measured in 2012. I'd like to suffix their names with "_2012". What's the easiest way to do this?

SPSS Python Syntax Example

begin program.
variables = 'v5 to v10' #Specify variables to be suffixed.
suffix ='_2012' # Specify suffix.
import spss,spssaux
oldnames = spssaux.VariableDict().expand(variables)
newnames = [varnam + suffix for varnam in oldnames]
spss.Submit('rename variables (%s=%s).'%('\n'.join(oldnames),'\n'.join(newnames)))
end program.

Description

Previous tutorial: Apply Dictionary Information from Excel

Next tutorial: Strip Prefix from Variable Labels

Let me know what you think!

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

This tutorial has 15 comments