1

I have two SPSS datasets (a & b) that have identical variable names (eg. date, time, etc.). I want to combine them without confusion. Therefore, I want to change the variable names to reflect the dataset it belongs to (a vs. b). How can I add "_a" to all the variable names in dataset a (eg. date_a). I would go through it manually except there are over a thousand variables in each dataset. I would prefer to keep everything in SPSS if possible. Help!

I tried the function below, but SPSS did not seem to like that and provided a lot of error messages indicating it did not recognize my variable names (I double-checked for typos and found none).

RENAME VARIABLES (expName=expName_a) (OS=OS_a) (framerate=frameRate_a) (trial.started.1=trial.started.1_a) 

1 Answer 1

0

Here is a way to do this using SPSS macro language:

* first we define a macro that takes a suffix and adds it to all variables in the list. define renameAll (!pos=!cmdend) !do !i !in(!eval(!allnms)) rename vars !i=!concat(!i,"_",!1). !doend. !enddefine. *once the macro is defined, we can open the file we want to work on. *in the example I assume it is already open and marked as dataset "a" but you can use a get data command here or whatever. dataset activate a. * this will create a list of all column names, stored in a macro called ! allnms. SPSSINC SELECT VARIABLES MACRONAME="!allnms". * now we can run the renaming macro, in this case using the suffix "a". renameAll a. 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.