Renaming entire set of variables by appending "_2"

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

Renaming entire set of variables by appending "_2"

Jennifer S. Randolph
Hello all-

I have a colleague with two SPSS datasets representing the same 500 variables collected on the same set of research subjects at time one and time two.  He would like to merge the two datasets, but the variables in the two datasets are identically named.  Given the high number of variables, it would be very time consuming to "rename" each variable one by one.  Is there a fast way to rename the entire set of variables (less the unique ID which he will merge on) by adding something akin to "_1" to all the time one variables and "_2" to all the time 2 variables to distinguish them?

We are using SPSS (PASW) 17.

Thank you.

Jennifer Stone Randolph, M.Sc.
Research Associate
Brain Imaging Laboratory
Department of Psychiatry

Confidentiality Notice: This e-mail transmission is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution violates confidentiality and privacy laws and is prohibited. If you are not the intended recipient, please contact the sender immediately and destroy all copies of the message. Thank you for your cooperation.

=====================
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: Renaming entire set of variables by appending "_2"

Bruce Weaver
Administrator
Something along these lines should do it.

ADD FILES
 file = "C:\MyFolder\File1.sav" / IN = time /
 file = "C:\MyFolder\File2.sav" .
recode time (0 = 2) (else=copy).
execute.

casestovars
 /id = IDvar
 /index = time
 /separator = '_' .

You may want to add some other sub-commands such as /GROUPBY, depending on what order you want the variables in after restructuring.  There may also be some variables to list on the /FIXED subcommand (e.g., any baseline variables that were measured only once).

HTH.


Jennifer S. Randolph wrote
Hello all-

I have a colleague with two SPSS datasets representing the same 500 variables collected on the same set of research subjects at time one and time two.  He would like to merge the two datasets, but the variables in the two datasets are identically named.  Given the high number of variables, it would be very time consuming to "rename" each variable one by one.  Is there a fast way to rename the entire set of variables (less the unique ID which he will merge on) by adding something akin to "_1" to all the time one variables and "_2" to all the time 2 variables to distinguish them?

We are using SPSS (PASW) 17.

Thank you.

Jennifer Stone Randolph, M.Sc.
Research Associate
Brain Imaging Laboratory
Department of Psychiatry

Confidentiality Notice: This e-mail transmission is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution violates confidentiality and privacy laws and is prohibited. If you are not the intended recipient, please contact the sender immediately and destroy all copies of the message. Thank you for your cooperation.

=====================
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
--
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: Renaming entire set of variables by appending "_2"

Richard Ristow
In reply to this post by Jennifer S. Randolph
At 10:15 AM 7/8/2011, Jennifer S. Randolph wrote:

>I have a colleague with two SPSS datasets representing the same 500
>variables collected on the same set of research subjects at time one
>and time two.  He would like to merge the two datasets, but the
>variables in the two datasets are identically named.  Given the high
>number of variables, it would be very time consuming to "rename"
>each variable one by one.

Bruce's CASESTOVARS is a good solution, though the ADD FILES should
have a BY clause so the datasets are interleaved, not catenated:

ADD FILES
   file = "C:\MyFolder\File1.sav" / IN = time
  /file = "C:\MyFolder\File2.sav"
  /BY IDvar .

recode time (0 = 2).

(followed by CASESTOVARS. I've omitted the 'COPY' clause on the
RECODE, and the "execute" statement, neither of which are necessary.)

An alternative that I recommend you consider is to interleave the
datasets with ADD FILES, but then not do the CASESTOVARS; that is,
leave two records per subject, one for each of the two times. You'll
probably find the data at least as easy to manage and analyze that way.

=====================
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: Renaming entire set of variables by appending "_2"

Bruce Weaver
Administrator
Nice catch, Richard.  I could echo David's comment from July 4 about posting untested code, but without the beverages or smoker.  ;-)



Richard Ristow wrote
At 10:15 AM 7/8/2011, Jennifer S. Randolph wrote:

>I have a colleague with two SPSS datasets representing the same 500
>variables collected on the same set of research subjects at time one
>and time two.  He would like to merge the two datasets, but the
>variables in the two datasets are identically named.  Given the high
>number of variables, it would be very time consuming to "rename"
>each variable one by one.

Bruce's CASESTOVARS is a good solution, though the ADD FILES should
have a BY clause so the datasets are interleaved, not catenated:

ADD FILES
   file = "C:\MyFolder\File1.sav" / IN = time
  /file = "C:\MyFolder\File2.sav"
  /BY IDvar .

recode time (0 = 2).

(followed by CASESTOVARS. I've omitted the 'COPY' clause on the
RECODE, and the "execute" statement, neither of which are necessary.)

An alternative that I recommend you consider is to interleave the
datasets with ADD FILES, but then not do the CASESTOVARS; that is,
leave two records per subject, one for each of the two times. You'll
probably find the data at least as easy to manage and analyze that way.

=====================
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
--
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: Renaming entire set of variables by appending "_2"

Bruce Weaver
Administrator
In reply to this post by Richard Ristow
Nice catch, Richard.  I could echo David's comment from July 4 about posting untested code.  I don't even have any excuses involving cold beverages or smokers.  ;-)


Richard Ristow wrote
At 10:15 AM 7/8/2011, Jennifer S. Randolph wrote:

>I have a colleague with two SPSS datasets representing the same 500
>variables collected on the same set of research subjects at time one
>and time two.  He would like to merge the two datasets, but the
>variables in the two datasets are identically named.  Given the high
>number of variables, it would be very time consuming to "rename"
>each variable one by one.

Bruce's CASESTOVARS is a good solution, though the ADD FILES should
have a BY clause so the datasets are interleaved, not catenated:

ADD FILES
   file = "C:\MyFolder\File1.sav" / IN = time
  /file = "C:\MyFolder\File2.sav"
  /BY IDvar .

recode time (0 = 2).

(followed by CASESTOVARS. I've omitted the 'COPY' clause on the
RECODE, and the "execute" statement, neither of which are necessary.)

An alternative that I recommend you consider is to interleave the
datasets with ADD FILES, but then not do the CASESTOVARS; that is,
leave two records per subject, one for each of the two times. You'll
probably find the data at least as easy to manage and analyze that way.

=====================
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
--
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/).