Trying to use SPSS/Python I would like change variable names for certain variables.
For example, I need all variables with the
oldname = t1XXX to change to newname = t01XXX
Tried to play with code I found around here (like below), but could not change this properly to do what I need. Thanks for any hints!
Example from Jignesh Sutar; strip-suffix-from-all-variable-names-in-spss/34816192#34816192)
begin program.
spss.Submit(r"set mprint on.")
import spss, spssaux
allvarlist=[str(v) for v in spssaux.VariableDict()]
filteredvarlist=[v for v in allvarlist if v.endswith("_1")]
spss.Submit( "rename variables (\n" \
+ "\n".join(filteredvarlist) \
+ "\n=\n" \
+ "\n".join([v[:-2] for v in filteredvarlist]) \
+ ").")
spss.Submit(r"set mprint off.")
end program.