Adding a Prefix to Variable Names

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

Adding a Prefix to Variable Names

Tim Pickles
Dear List,

Data Managers in my office have cut corners and put similar data from
different timepoints in the same excel file. I therefore want to open this
into SPSS (fine), split it into n separate datasets (depending on the
number of timepoints) and then change the name of the variables in those
datasets to reflect when they were recorded, so for timepoint 1, I want all
variables to start 'T1'. There are quite a lot of variables here and whilst
I know it is possible to rename each of them separately with the relevant
prefix, is there a way of doing this as a group of variables?

Cheers,
Tim.

=====================
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: Adding a Prefix to Variable Names

Nirit Avnimelech

My primitive solution would be:

 

1.  Copy the "base" var names into Excel, starting at col. 1 row 2.

2.  Starting in col. 2 row 1 produce a list of consecutive numbers

3.  In col. 2 row 2 insert the function: =concatenate("t",B$1,"_",$A2)

4.  Relative copy this function into the rest of the relevant cells

5.  You now have t columns, with the specific v variables (named t1_var1, t1_var2...., t2_var1, t2_var2..., etc):

 

 

1

2

3

4

 

 

var1

t1_var1

t2_var1

t3_var1

t4_var1

 

 

var2

t1_var2

t2_var2

t3_var2

t4_var2

 

 

var3

t1_var3

t2_var3

t3_var3

t4_var3

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

6.  Now you can copy the new var names into the variables tab of the data file.

 

Alternatively, use the same concatenate function in Excel to produce the RENAME VARIABLES command and plant it in syntax.

 

If you’re more sophisticated than that, then you can use the DO REPEAT command to do it automatically.

 

Nirit

 

 

 

 

 

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Tim Pickles
Sent: Thursday, July 08, 2010 2:38 PM
To: [hidden email]
Subject: Adding a Prefix to Variable Names

 

Dear List,

 

Data Managers in my office have cut corners and put similar data from

different timepoints in the same excel file. I therefore want to open this

into SPSS (fine), split it into n separate datasets (depending on the

number of timepoints) and then change the name of the variables in those

datasets to reflect when they were recorded, so for timepoint 1, I want all

variables to start 'T1'. There are quite a lot of variables here and whilst

I know it is possible to rename each of them separately with the relevant

prefix, is there a way of doing this as a group of variables?

 

Cheers,

Tim.

 

=====================

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: Adding a Prefix to Variable Names

Ruben Geert van den Berg
A basic Python solution (I think from Albert-Jan?) is
 
begin program python.
import spssaux, spss
vs = spssaux.GetVariableNamesList()
spss.Submit("rename variables (%s = %s)." % ( " ".join(vs), " ".join(["T1_" + v for v in vs]) ) )
end program.

It will add "T1_" as a prefix to all your variables. If you want only a subset, it'll get a bit more complicated...and I don't have a lot of time now.
 
Alternatively, you can write syntax generating syntax to accomplish it. For which I've no time either...
 
HTH,

Ruben van den Berg
Consultant Models & Methods
TNS NIPO
Email: [hidden email]
Mobiel: +31 6 24641435
Telefoon: +31 20 522 5738
Internet: www.tns-nipo.com



 

Date: Thu, 8 Jul 2010 15:08:31 +0300
From: [hidden email]
Subject: Re: Adding a Prefix to Variable Names
To: [hidden email]

My primitive solution would be:

 

1.  Copy the "base" var names into Excel, starting at col. 1 row 2.

2.  Starting in col. 2 row 1 produce a list of consecutive numbers

3.  In col. 2 row 2 insert the function: =concatenate("t",B$1,"_",$A2)

4.  Relative copy this function into the rest of the relevant cells

5.  You now have t columns, with the specific v variables (named t1_var1, t1_var2...., t2_var1, t2_var2..., etc):

 

 

1

2

3

4

 

 

var1

t1_var1

t2_var1

t3_var1

t4_var1

 

 

var2

t1_var2

t2_var2

t3_var2

t4_var2

 

 

var3

t1_var3

t2_var3

t3_var3

t4_var3

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

6.  Now you can copy the new var names into the variables tab of the data file.

 

Alternatively, use the same concatenate function in Excel to produce the RENAME VARIABLES command and plant it in syntax.

 

If you’re more sophisticated than that, then you can use the DO REPEAT command to do it automatically.

 

Nirit

 

 

 

 

 

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Tim Pickles
Sent: Thursday, July 08, 2010 2:38 PM
To: [hidden email]
Subject: Adding a Prefix to Variable Names

 

Dear List,

 

Data Managers in my office have cut corners and put similar data from

different timepoints in the same excel file. I therefore want to open this

into SPSS (fine), split it into n separate datasets (depending on the

number of timepoints) and then change the name of the variables in those

datasets to reflect when they were recorded, so for timepoint 1, I want all

variables to start 'T1'. There are quite a lot of variables here and whilst

I know it is possible to rename each of them separately with the relevant

prefix, is there a way of doing this as a group of variables?

 

Cheers,

Tim.

 

=====================

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: Adding a Prefix to Variable Names

John F Hall
In reply to this post by Tim Pickles
Tim
 
Send more info (ie extract from data)
 
Art Kendall sent me some syntax for a similar problem.  You can probably adapt it.  It produces a new Data Editor (make sure you save it before copying from it!)
 
Another trick might be to read in your vars from Excel and then use
 
rename variables
 
to change the names.
 
Here's an extract from the files (adapted from Art's) I just used:
 
data list fixed /item (3x, f3.0) itemlabel(1x, a90).
begin data
  (794)No, my strengths are in other areas
  (795)No, my parents say that other jobs are better
  (796)No, teaching does not interest me
. . .
 end data.
print  /'     ' item '"' itemlabel '"/'.
execute.
 
and here's one I wrote to rename vars:
 
rename variables
 (token_id.568 to token_id.578 token_id.579 to token_id.598
 = token568 to token578 token579 to token598).
execute.
 
..but I see others more expert than I have already replied.
 
John Hall
----- Original Message -----
Sent: Thursday, July 08, 2010 1:38 PM
Subject: Adding a Prefix to Variable Names


Dear List,

Data Managers in my office have cut corners and put similar data from
different timepoints in the same excel file. I therefore want to open this
into SPSS (fine), split it into n separate datasets (depending on the
number of timepoints) and then change the name of the variables in those
datasets to reflect when they were recorded, so for timepoint 1, I want all
variables to start 'T1'. There are quite a lot of variables here and whilst
I know it is possible to rename each of them separately with the relevant
prefix, is there a way of doing this as a group of variables?

Cheers,
Tim.

=====================
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: Adding a Prefix to Variable Names

Bruce Weaver
Administrator
In reply to this post by Ruben Geert van den Berg
Here's an old-school BP* method:

   http://www.spsstools.net/Syntax/LabelsAndVariableNames/ChangeCharacterAtBeginningOfEachVarNames.txt

Obviously, it could now be modified to allow variable names longer than 8 characters, and two datasets could be used rather than writing files to disk, etc.

And yes, Jon, I do know how much you despise the approach of creating a syntax file which is then included (or inserted).  ;-)


*  BP = Before Python


Ruben van den Berg wrote
A basic Python solution (I think from Albert-Jan?) is

 

begin program python.
import spssaux, spss
vs = spssaux.GetVariableNamesList()
spss.Submit("rename variables (%s = %s)." % ( " ".join(vs), " ".join(["T1_" + v for v in vs]) ) )
end program.


It will add "T1_" as a prefix to all your variables. If you want only a subset, it'll get a bit more complicated...and I don't have a lot of time now.

 

Alternatively, you can write syntax generating syntax to accomplish it. For which I've no time either...

 

HTH,

Ruben van den Berg
Consultant Models & Methods
TNS NIPO
Email: ruben.van.den.berg@tns-nipo.com
Mobiel: +31 6 24641435
Telefoon: +31 20 522 5738
Internet: www.tns-nipo.com



 


Date: Thu, 8 Jul 2010 15:08:31 +0300
From: niritav@gmail.com
Subject: Re: Adding a Prefix to Variable Names
To: SPSSX-L@LISTSERV.UGA.EDU





My primitive solution would be:
 
1.  Copy the "base" var names into Excel, starting at col. 1 row 2.
2.  Starting in col. 2 row 1 produce a list of consecutive numbers
3.  In col. 2 row 2 insert the function: =concatenate("t",B$1,"_",$A2)
4.  Relative copy this function into the rest of the relevant cells
5.  You now have t columns, with the specific v variables (named t1_var1, t1_var2...., t2_var1, t2_var2..., etc):
 




 

1

2

3

4

 

 


var1

t1_var1

t2_var1

t3_var1

t4_var1

 

 


var2

t1_var2

t2_var2

t3_var2

t4_var2

 

 


var3

t1_var3

t2_var3

t3_var3

t4_var3

 

 


 

 

 

 

 

 

 


 

 

 

 

 

 

 
 
6.  Now you can copy the new var names into the variables tab of the data file.
 
Alternatively, use the same concatenate function in Excel to produce the RENAME VARIABLES command and plant it in syntax.
 
If you’re more sophisticated than that, then you can use the DO REPEAT command to do it automatically.
 
Nirit
 
 
 
 
 
-----Original Message-----
From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Tim Pickles
Sent: Thursday, July 08, 2010 2:38 PM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: Adding a Prefix to Variable Names
 
Dear List,
 
Data Managers in my office have cut corners and put similar data from
different timepoints in the same excel file. I therefore want to open this
into SPSS (fine), split it into n separate datasets (depending on the
number of timepoints) and then change the name of the variables in those
datasets to reflect when they were recorded, so for timepoint 1, I want all
variables to start 'T1'. There are quite a lot of variables here and whilst
I know it is possible to rename each of them separately with the relevant
prefix, is there a way of doing this as a group of variables?
 
Cheers,
Tim.
 
=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@LISTSERV.UGA.EDU (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.
http://windows.microsoft.com/shop
--
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
|

difference or complementarity between Kappa (or its generalizations) and Kendall's concordance coefficient W

Placide-2
In reply to this post by Ruben Geert van den Berg
Dear All,
I am wondering if some one can explain and/or provide references for the difference or complementarity between Kappa coefficient (or its generalizations) and Kendall's concordance coefficient W
Thank you for your help.
Placide
 

Reply | Threaded
Open this post in threaded view
|

Re: Adding a Prefix to Variable Names

Wilhelm Landerholm | Queue
In reply to this post by Ruben Geert van den Berg
Hi there!

I know that there are many using SPSS and do not use the Python Plugin; so if you want to run rename on a whole dataset (similar to Rubens Python) you can also use this script. Just copy the text and save as an SBS-file.

All the best

Wilhelm (Wille) Landerholm
+46-735-460000

Queue/STATB
BOX 92
162 12 Vallingby
Sweden

http://www.qsweden.com
http://www.statb.com

QUEUE/STATB - your partner in data analysis, data modeling and data mining.


2010/7/8 Ruben van den Berg <[hidden email]>
A basic Python solution (I think from Albert-Jan?) is

 
begin program python.
import spssaux, spss
vs = spssaux.GetVariableNamesList()
spss.Submit("rename variables (%s = %s)." % ( " ".join(vs), " ".join(["T1_" + v for v in vs]) ) )
end program.

It will add "T1_" as a prefix to all your variables. If you want only a subset, it'll get a bit more complicated...and I don't have a lot of time now.
 
Alternatively, you can write syntax generating syntax to accomplish it. For which I've no time either...
 
HTH,

Ruben van den Berg
Consultant Models & Methods
TNS NIPO
Email: [hidden email]
Mobiel: +31 6 24641435
Telefoon: +31 20 522 5738
Internet: www.tns-nipo.com



 

Date: Thu, 8 Jul 2010 15:08:31 +0300
From: [hidden email]
Subject: Re: Adding a Prefix to Variable Names

To: [hidden email]

My primitive solution would be:

 

1.  Copy the "base" var names into Excel, starting at col. 1 row 2.

2.  Starting in col. 2 row 1 produce a list of consecutive numbers

3.  In col. 2 row 2 insert the function: =concatenate("t",B$1,"_",$A2)

4.  Relative copy this function into the rest of the relevant cells

5.  You now have t columns, with the specific v variables (named t1_var1, t1_var2...., t2_var1, t2_var2..., etc):

 

 

1

2

3

4

 

 

var1

t1_var1

t2_var1

t3_var1

t4_var1

 

 

var2

t1_var2

t2_var2

t3_var2

t4_var2

 

 

var3

t1_var3

t2_var3

t3_var3

t4_var3

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

6.  Now you can copy the new var names into the variables tab of the data file.

 

Alternatively, use the same concatenate function in Excel to produce the RENAME VARIABLES command and plant it in syntax.

 

If you’re more sophisticated than that, then you can use the DO REPEAT command to do it automatically.

 

Nirit

 

 

 

 

 

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Tim Pickles
Sent: Thursday, July 08, 2010 2:38 PM
To: [hidden email]
Subject: Adding a Prefix to Variable Names

 

Dear List,

 

Data Managers in my office have cut corners and put similar data from

different timepoints in the same excel file. I therefore want to open this

into SPSS (fine), split it into n separate datasets (depending on the

number of timepoints) and then change the name of the variables in those

datasets to reflect when they were recorded, so for timepoint 1, I want all

variables to start 'T1'. There are quite a lot of variables here and whilst

I know it is possible to rename each of them separately with the relevant

prefix, is there a way of doing this as a group of variables?

 

Cheers,

Tim.

 

=====================

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.