On Mon, 18 May 2020 06:58:05 -0700 (PDT), Vibeke Nielsen <
[email protected]> wrote:
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.
Bruce gave you the better solution, if you have the file
available - create the desired names and never see the others.
Or, you can use Find and Replace in the syntax editor, writing
a small task to rename variables; Execute and Save .
To change the names of variables (from the manual) -
Use the command RENAME VARIABLES. An example would be
RENAME VARIABLES (V1 V2 V3 = NEW1 NEW2 NEW3).
So -
Write out Rename variables
( < insert variable list > =
< insert variable list a second time > ).
Use Find and Replace on the SECOND LIST only,
to change .1 to _C1 and .2 to _C2.
--
Rich Ulrich
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)