Rename variables with the string value in another variable?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Rename variables with the string value in another variable?

Simon Kiss
Hi there, I have a large dataset, but I'm interested in renaming
aseries of variables var00001 to var00019.
riding_e             var00001 .... to        var00019.
string value1            numeric               numeric
string value 2
string value 3
stringe value 4
I would like var00001 to be renamed string value 1, var00002 to be
renamend string value 2, var00003 to be renamed string value 3.

Can someone suggest a syntax for me?
Simon Kiss


*********************************
Simon J. Kiss, PhD
SSHRC and DAAD Post-Doctoral Fellow
John F. Kennedy Institute of North America Studies
Free University of Berlin
Lansstraße 7-9
14195 Berlin, Germany
Cell: +49 (0)1525-300-2812,
Web: http://www.jfki.fu-berlin.de/index.html

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Rename variables with the string value in another variable?

Ruben Geert van den Berg
Dear Simon,

 

'string value 1' is not a valid variable name since it contains spaces. If I replace those by underscores, then

 

ren var (var00001 to var00019=string_value_1 to string_value_19)./*ren var=rename variables.
 
(untested) should work.
 
HTH!

Ruben van den Berg

Methodologist

TNS NIPO

E: [hidden email]

P: +31 20 522 5738

I: www.tns-nipo.com




 

> Date: Mon, 25 Jan 2010 15:05:14 +0100
> From: [hidden email]
> Subject: Rename variables with the string value in another variable?
> To: [hidden email]
>
> Hi there, I have a large dataset, but I'm interested in renaming
> aseries of variables var00001 to var00019.
> riding_e var00001 .... to var00019.
> string value1 numeric numeric
> string value 2
> string value 3
> stringe value 4
> I would like var00001 to be renamed string value 1, var00002 to be
> renamend string value 2, var00003 to be renamed string value 3.
>
> Can someone suggest a syntax for me?
> Simon Kiss
>
>
> *********************************
> Simon J. Kiss, PhD
> SSHRC and DAAD Post-Doctoral Fellow
> John F. Kennedy Institute of North America Studies
> Free University of Berlin
> Lansstraße 7-9
> 14195 Berlin, Germany
> Cell: +49 (0)1525-300-2812,
> Web: http://www.jfki.fu-berlin.de/index.html
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD


New Windows 7: Find the right PC for you. Learn more.
Reply | Threaded
Open this post in threaded view
|

Re: Rename variables with the string value in another variable?

Bruce Weaver
Administrator

Ruben van den Berg wrote
Dear Simon,
 
'string value 1' is not a valid variable name since it contains spaces. If I replace those by underscores, then
 
ren var (var00001 to var00019=string_value_1 to string_value_19)./*ren var=rename variables.

Ruben, I think what Simon meant was that the desired variable names appear in the RIDING_E column in the data file.   Something along these lines should work, I think.

new file.
dataset close all.

* Create a sample data set with only 3 variables .

data list list / riding_e (a8) var1 to var3 (3f2.0).
begin data
"newvar1" 1 2 3
"newvar2" 3 1 2
"newvar3" 3 2 1
end data.

string #case (a2).
compute #case = ltrim(string($casenum,f1)).
write outfile = "C:\temp\rename.txt" /
 "rename var(var", #case," = ", riding_e,")." .
exe.

include file = "C:\temp\rename.txt" .

Cheers,
Bruce

p.s. - It would not surprise me if there's a nice Python-based solution too.  ;-)

--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Rename variables with the string value in another variable?

Albert-Jan Roskam
In reply to this post by Simon Kiss
Hi Simon,

Untested:
import spss, spssaux
vlist = spssaux.GetVariableNamesList()
curs = spss.Cursor([vlist.index("riding_e")])
newnames = " ".join(curs.fetchall()[:19])
curs.close()
spss.Submit("rename variables (var00001 to var00019 = %s)." % newnames)

Cheers!!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In the face of ambiguity, refuse the temptation to guess.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--- On Mon, 1/25/10, Simon Kiss <[hidden email]> wrote:

From: Simon Kiss <[hidden email]>
Subject: [SPSSX-L] Rename variables with the string value in another variable?
To: [hidden email]
Date: Monday, January 25, 2010, 3:05 PM

Hi there, I have a large dataset, but I'm interested in renaming
aseries of variables var00001 to var00019.
riding_e             var00001 .... to        var00019.
string value1            numeric               numeric
string value 2
string value 3
stringe value 4
I would like var00001 to be renamed string value 1, var00002 to be
renamend string value 2, var00003 to be renamed string value 3.

Can someone suggest a syntax for me?
Simon Kiss


*********************************
Simon J. Kiss, PhD
SSHRC and DAAD Post-Doctoral Fellow
John F. Kennedy Institute of North America Studies
Free University of Berlin
Lansstraße 7-9
14195 Berlin, Germany
Cell: +49 (0)1525-300-2812,
Web: http://www.jfki.fu-berlin.de/index.html

=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@... (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD