• Remove suffix from variable names

    From winterversion@21:1/5 to All on Fri Aug 20 12:25:41 2021
    Hello,

    I have a suffix, "_t1" that I would like to remove from all of my variables. Is there a handy set of syntax to do this for all of my variables at once rather than having rename them all one by one?

    Thanks in advance!
    Paul

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich Ulrich@21:1/5 to paulkim16@hotmail.com on Sat Aug 21 01:37:46 2021
    On Fri, 20 Aug 2021 12:25:41 -0700 (PDT), winterversion
    <paulkim16@hotmail.com> wrote:

    Hello,

    I have a suffix, "_t1" that I would like to remove from all of my variables. Is there a handy set of syntax to do this for all of my variables at once rather than having rename them all one by one?

    Thanks in advance!

    There's probably a way using Python, if you use Python in SPSS.

    I've used the brute force method. Copy the variable list twice and
    shorten the second set of names. Finish the syntax as appropriate.

    The syntax guide gives the RENAME example, for two variables -
    RENAME VARIABLES (MOHIRED YRHIRED=MOSTART YRSTART).


    That was convenient since I did have a simple list of variables
    and I regularly used an editor with a useful SUBSTITUTE command.
    Substitute (for your case) "_t1" to blank for a given set of lines.
    I don't know what the SPSS syntax editor can do.

    --
    Rich Ulrich

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From winterversion@21:1/5 to All on Mon Aug 23 13:01:21 2021
    Thank you Rich! I actually discovered that you can do "find/replace" under the variable view tab. When you highlight the column with all the variable names and press control F, you can do a replace "_t1" with a blank, and that worked.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich Ulrich@21:1/5 to paulkim16@hotmail.com on Tue Aug 24 11:35:22 2021
    On Mon, 23 Aug 2021 13:01:21 -0700 (PDT), winterversion
    <paulkim16@hotmail.com> wrote:

    Thank you Rich! I actually discovered that you can do "find/replace" under the variable view tab. When you highlight the column with all the variable names and press control F, you can do a replace "_t1" with a blank, and that worked.


    Great! You improved on the solution! (at least, for the
    one-time requirement).

    I'm thinking, there is a potential advantage of the solution
    done by tedious syntax -- In my experience of analyzing data
    from other people, it is not uncommon for them to want to
    edit some values in the set, or to add a few cases... or even
    do the whole thing with some other data. Having syntax
    (a) documents the process and (b) allows for instant re-runs.

    Leaving everything useful in (saved) syntax is a good idea in
    the long run, even if you have interactive experiments that you
    throw away.


    --
    Rich Ulrich

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Bruce Weaver@21:1/5 to Rich Ulrich on Sat Aug 28 08:54:02 2021
    Here's some Python code that seems relevant:

    https://www.py4u.net/discuss/209789

    The UCLA link it includes is out of date. I suspect that this is the current version of the page that was intended:

    https://stats.idre.ucla.edu/spss/faq/how-can-i-write-a-python-program-to-rename-variables-in-spss/

    HTH.


    On Tuesday, August 24, 2021 at 11:35:30 AM UTC-4, Rich Ulrich wrote:
    On Mon, 23 Aug 2021 13:01:21 -0700 (PDT), winterversion
    <paul...@hotmail.com> wrote:

    Thank you Rich! I actually discovered that you can do "find/replace" under the variable view tab. When you highlight the column with all the variable names and press control F, you can do a replace "_t1" with a blank, and that worked.
    Great! You improved on the solution! (at least, for the
    one-time requirement).

    I'm thinking, there is a potential advantage of the solution
    done by tedious syntax -- In my experience of analyzing data
    from other people, it is not uncommon for them to want to
    edit some values in the set, or to add a few cases... or even
    do the whole thing with some other data. Having syntax
    (a) documents the process and (b) allows for instant re-runs.

    Leaving everything useful in (saved) syntax is a good idea in
    the long run, even if you have interactive experiments that you
    throw away.


    --
    Rich Ulrich

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)