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

renaming multiple variables

4,685 views
Skip to first unread message

WWW Support

unread,
Jan 8, 1997, 3:00:00 AM1/8/97
to

Gloria,

There is indeed a RENAME VARIABLES command.
If the variable names are constructed as you describe
here, your client can use the TO convention available
in a number of SPSS commands to specify a range of
contiguous variables. For example,

RENAME VARIABLES (v1 TO v10 = v11 TO v20)

will do pretty much what it appears to be doing, and eliminate
the need to specify each renamed variable individually.
See the RENAME VARIABLES command description
in the SPSS Syntax Reference Guide associated with
your version of the software for more details.

I hope this information is useful to you,

Ed Tverdek
SPSS Technical Support

>----------
>From: Gloria Edwards[SMTP:gsed...@hamlet.uncg.edu]
>Sent: Wednesday, January 08, 1997 10:12 AM
>To: Multiple recipients of list SPSSX-L
>Subject: renaming multiple variables
>
>I have a client who wants to merge three datasets. The problem is that
>the datasets have duplicate variable names (e.g., v1-v225) that represent
>different things in each dataset. Therefore, the variables need to be
>renamed before merging.
>
>Is there a way to rename multiple variables in SPSS without specifying
>each variable individually? The datasets are so large that individual
>renames would be extremely cumbersome, but the menu options in SPSS Win
>7.0 didn't appear to provide a work around. Can we do this with syntax
>
>Any help would be appreciated.
>
>Thanks,
>
>Gloria Edwards
>Instructional and Research Computing
>235 Bryan Building
>UNC Greensboro
>(910)334-5350
>

Gloria Edwards

unread,
Jan 8, 1997, 3:00:00 AM1/8/97
to

peter homel

unread,
Jan 9, 1997, 3:00:00 AM1/9/97
to

This may not be feasible for Gloria Edward's problem, but I have found
a quick and not so dirty way of renaming variables from multiple files
where there are duplicate variable names. The trick is to merge the
files first in a program that does allow for duplicate "variable names".
Thie can be done, for example, in Excel (using copy and paste, say).

When you bring the Excel file into SPSS, SPSS will automatically rename
duplicate variable names by adding a numeral to the duplicate
variable names. For example, say you bring in an Excel file which contains the
following column names: X1 X2 X11 X1 X2 X11 X1 X2 X11. SPSS will rename these
as X1 X2 X11 X12 X21 X111 X13 X22 X112. It can be seen that SPSS simply adds
a numeral that will make the renamed variable unique (e.g., X2 -> X21 in
the first duplicate, X2 -> X22 in the second duplicate). SPSS always checks
to see whether renaming the variable will result in another duplication.
Since X11 already exists, X1 -> X12 in the first duplicate while X1 ->
X13 in the second duplicate.

This tends to work fairly well with variable names that do not end with
numerals. SPSS will truncate variable names before adding numerals in
order to keep within the eight character limit for variables names.
Working with variable names that already end in numerals may make it
confusing you to tell which ones come from which file (although that
can be done based on the order of the variables in the file).

Another problem that precludes using this method for Gloria Edwards data
is that (as far as I know) Excel is limited to 255 (256?0 columns which would
not be enough for what Gloria is doing. Anyway, this method works fine for
small files with not too many variables.

PETER HOMEL PHD
HEALTH SCIENCE CENTER BROOKLYN
STATE UNIVERSITY OF NEW YORK
450 CLARKSON AVENUE BOX 7
BROOKLYN, NY 11203-2098

EMAIL: HO...@SACC.HSCBKLYN.EDU
HO...@SNYBKSAC.BITNET

TEL: (718) 270-7424
FAX: (718) 270-7461

MOTTO: STATISTICS DON'T LIE!(PEOPLE DO!)

Melvin Klassen

unread,
Jan 9, 1997, 3:00:00 AM1/9/97
to

Gloria Edwards <gsed...@HAMLET.UNCG.EDU> writes:
>I have a client who wants to merge three datasets. The problem is that
>the datasets have duplicate variable names (e.g., v1-v225) that represent
>different things in each dataset. Therefore, the variables need to be
>renamed before merging.
>Is there a way to rename multiple variables in SPSS without specifying
>each variable individually? The datasets are so large that individual
>renames would be extremely cumbersome, but the menu options in SPSS Win
>7.0 didn't appear to provide a work around. Can we do this with syntax?

MATCH FILES FILE= handle1 /
RENAME= (V1 TO V225 = A1 TO A225) /
IN = INA /

FILE= handle2 /
RENAME= (V1 TO V225 = B1 TO B225) /
IN = INB /

BY varlist /

SELECT IF (INA AND INB) /* Select only "matching" cases. */

QED.

Jens Boelte

unread,
Jan 10, 1997, 3:00:00 AM1/10/97
to

> ----------------------------Original message----------------------------
> I have a client who wants to merge three datasets. The problem is that
> the datasets have duplicate variable names (e.g., v1-v225) that represent
> different things in each dataset. Therefore, the variables need to be
> renamed before merging.
>
> Is there a way to rename multiple variables in SPSS without specifying
> each variable individually? The datasets are so large that individual
> renames would be extremely cumbersome, but the menu options in SPSS Win
> 7.0 didn't appear to provide a work around. Can we do this with syntax
>

Does not the command "match files" do the job, e.g.

match files file=update /rename(v1 to v225 = n1 to n225)
/file=master
/by id.

In this example the variables v1 to v225 are renamed to n1 to n225 before
the files are matched. The id variables ensures that only cases with the
same id are matched (examples taken from the SPSS reference guide, pp.403).

If you simply want to concatenate two or more files, you rather use the
command "add files". The syntax is the same as for the "match files"
command.

add files file=file1
/rename(v1 to v225 = n1 to n225)
/file=file2
/rename(w1 to w225 = o1 to o225)
/file=file3.

with many regards

Jens Boelte
-------------------------------
Psychologisches Institut II
Fliedner Str. 21
48149 Muenster
Germany

0 new messages