Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Remove suffix from variable names

150 views
Skip to first unread message

winterversion

unread,
Aug 20, 2021, 3:25:43 PM8/20/21
to
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

Rich Ulrich

unread,
Aug 21, 2021, 1:37:55 AM8/21/21
to
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

winterversion

unread,
Aug 23, 2021, 4:01:23 PM8/23/21
to
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.

Rich Ulrich

unread,
Aug 24, 2021, 11:35:30 AM8/24/21
to
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

Bruce Weaver

unread,
Aug 28, 2021, 11:54:04 AM8/28/21
to
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.
0 new messages