79120585

Date: 2024-10-24 06:23:35
Score: 1.5
Natty:
Report link

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).

Reasons:
  • Blacklisted phrase (1): help me
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Gizi