I'm planning to merge data from different sets, but before I do I'd like to add prefixes to all variables in each dataset so that we can later easily determine where the variables initially came from. I've seen macros for adding suffixes, removing prefixes, etc. and I've tried to modify these for my own purposes, but I haven't had luck.
I saw this macro shared by another user on a similar post and edited. Here, I'm trying to add "SA" to all variables:
define AddSAPrefix (varlist=!cmdend)
rename vars
!do !v !in(!varlist) !concat("SA",!v, " = ", !v) !doend .
!enddefine.
AddSAPrefix varlist = ClientID to MostRecentDeRegistrationDate.
However, when I run this nothing happens and I get multiple errors:
Can anyone explain why this isn't working?
The problem is just that in SPSS when you want to rename variables you have to state the existing_name=new_name, you did the reverse. So try:
!do !v !in(!varlist) !concat(!v, " = ", "SA", !v) !doend .
Also you can simplify like this:
!do !v !in(!varlist) !v = !concat("SA", !v)
!doend .