I want to rename a list of variables in a dataset that has thousands of variables. There are certain patterns in the renaming process and I tried to write a macro for this.
I want to drop the last character of the variable's name and concatenate it with new characters(this part works fine)
Here is the macro. it does not work but the output file is of no use this time:
define !rename4 (vlist = !charend('/'))
!let !count = 1
!let !incr = 1
!do !vname !in (!vlist)
!let !lastcharacter = !char.length(!vname)
!let !newname0 = !char.substr(!vname, 1, !lastcharacter) \*\*
!let !newname1 = !concat(!newname0,"\_")
!let !newname = !concat(!newname1, !count)
rename variables (!vname = !newname)
!let !count = !length(!concat(!blank(!count), !blank(!incr)))
!doend
!enddefine.