Vibeke Nielsen
2020-05-18 13:58:05 UTC
Using 'restructure cases into variables' I have converted a SPSS file in long format (child/twin level) to wide format (family level). The variables that differ between the twin-members (child 1 is firstborn twin-member, child 2 is second-born twin-member) of one family ( e.g. handedness, IQ) now end at .1 for child 1 and .2 for child 2. For all those variables (string and numeric variables) I would like to rename them in order that .1 becomes _C1 and .2 becomes _C2. All variables names have different length but all end at '.1' or '.2'.
So for example, I have data concerning IQ and handedness of a twin pair: WISC_TIQ.1 and Handedness.1 which represents IQ and handedness of child 1, and WISC_TIQ.2 and Handedness.2 which represents IQ and handedness of child 2. Instead of renaming all those variables by hand, I wondered how to use loops to rename all these different variables ending at .1 into different variables all ending at _C1 and all variables ending at .2 into variables ending at _C2.
On https://stats.idre.ucla.edu/spss/code/a-few-spss-loops-for-renaming-variables-dynamically/, I read something about using a macro and loops for this, but as I am quite new to SPSS I fail to rewrite the examples on those sites to my issue.
Some suggest using the python extension, but unfortunately, the remote system of my university does not allow reïnstalling SPSS 25 to install the python plugin.
I hope someone can help me.
So for example, I have data concerning IQ and handedness of a twin pair: WISC_TIQ.1 and Handedness.1 which represents IQ and handedness of child 1, and WISC_TIQ.2 and Handedness.2 which represents IQ and handedness of child 2. Instead of renaming all those variables by hand, I wondered how to use loops to rename all these different variables ending at .1 into different variables all ending at _C1 and all variables ending at .2 into variables ending at _C2.
On https://stats.idre.ucla.edu/spss/code/a-few-spss-loops-for-renaming-variables-dynamically/, I read something about using a macro and loops for this, but as I am quite new to SPSS I fail to rewrite the examples on those sites to my issue.
Some suggest using the python extension, but unfortunately, the remote system of my university does not allow reïnstalling SPSS 25 to install the python plugin.
I hope someone can help me.