I managed to solve the problem, the following way:
define !rename4 (vlist = !charend('/'))
!let !count = 1
!let !incr = 1
!let !incrtwo=2
!let !subtr=-1
!do !vname !in (!vlist)
!let !len=!length(!vname)
!let !lastbutonecharacter = !length(!concat(!blank(!len), !blank(!subtr)))
!let !lastletter= !substr(!vname, !len, !incr)
!if (!lastletter = A) !then
!let !count=1
!ifend
!let !newname0 = !substr(!vname, 1, !lastbutonecharacter)
!let !newname1 = !concat(!newname0,"_")
!let !newname = !concat(!newname1, !count)
rename variables (!vname = !newname).
!let !count = !length(!concat(!blank(!count), !blank(!incr)))
!doend
!enddefine.
the main problem was that I had no idea about what commands I can use in an SPSS macro. In the IBM community Jon Oeck helped me out: it can be found in SPSS help menu in the command syntax reference (under define-enddefine).