RENAME LOOP?

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

RENAME LOOP?

Karen Powers-2
Hello SPSS list,
I have a dataset in which the variable names are var002, var003   ...
var3477.

I would like to RENAME each variable with the number listed in row 1 of
each respective column.
The first number in var002 is 6951030.  I would like var002 renamed
"rs6951030".
The command for doing this once that runs nicely is:

RENAME VARS var002 = "rs"+ "6951030".
EXE.

Now I would like to do this for all vars through var3477.
I have tried DO REPEAT and LOOP commands but they both say
 >Warning # 141.  Command name: RENAME VARS
 >DO REPEAT has no effect on this command.

Any ideas on how I can do this (3477 times)?

Thanks, Karen
Reply | Threaded
Open this post in threaded view
|

Re: RENAME LOOP?

Raynald Levesque-2
Hi Karen,

This is one way:

CD 'C:\temp'.

DATA LIST LIST /id var002 TO var006.
BEGIN DATA
9 2552 4215 4812 2400 65984
1 1 2 3 4 5
2 4 5 6 9 8
3 1 1 1 1 1
END DATA.
SAVE OUTFILE='original data.sav'.

GET FILE='original data.sav' /KEEP=var002 TO var006.
N OF CASES 1.
VECTOR v=var002 TO var006.
STRING newname(A18).
LOOP idx=2 TO 6.
- COMPUTE newname=CONCAT('var', LTRIM(STRING(v(idx - 1),F8))).
- FORMATS idx (N3).
- WRITE OUTFILE='syntax to rename.sps'
    /'RENAME VARIABLES (var', idx ,' = ', newname, ').'.
END LOOP.
EXECUTE.

GET FILE='original data.sav'.
INSERT FILE='syntax to rename.sps' .

Cheers!

Raynald Levesque
www.spsstools.net


On 7/25/07, Karen Powers <[hidden email]> wrote:

>
> Hello SPSS list,
> I have a dataset in which the variable names are var002, var003   ...
> var3477.
>
> I would like to RENAME each variable with the number listed in row 1 of
> each respective column.
> The first number in var002 is 6951030.  I would like var002 renamed
> "rs6951030".
> The command for doing this once that runs nicely is:
>
> RENAME VARS var002 = "rs"+ "6951030".
> EXE.
>
> Now I would like to do this for all vars through var3477.
> I have tried DO REPEAT and LOOP commands but they both say
> >Warning # 141.  Command name: RENAME VARS
> >DO REPEAT has no effect on this command.
>
> Any ideas on how I can do this (3477 times)?
>
> Thanks, Karen
>
Reply | Threaded
Open this post in threaded view
|

Re: RENAME LOOP?

Hal 9000
In reply to this post by Karen Powers-2
wellllllll.................

This Does work:


************************************************.

new file.
data list free/ var001 var002 var003.
begin data
111 222 333
444 555 666
end data.

set mprint on.

define @A (B = !charend('/'))
!do !C !in (!B)
do if $casenum = 1.
write outfile = 'c:\temp\Rename.sps'
        /'define !D () ' !C ' !enddefine.'.
end if.
exe.
insert file = 'c:\temp\Rename.sps'.
rename variables ( !C = !concat('sr', !eval(!D))).
!doend
!enddefine.


@A B = var001 var002 var003/.
**************************************************************.

...But it only seems to work the first time it's run in a session! And
I don't know why at this moment. I'll figure it out, but if anybody
cares to say, I welcome the feedback.

-Gary



On 7/25/07, Karen Powers <[hidden email]> wrote:

> Hello SPSS list,
> I have a dataset in which the variable names are var002, var003   ...
> var3477.
>
> I would like to RENAME each variable with the number listed in row 1 of
> each respective column.
> The first number in var002 is 6951030.  I would like var002 renamed
> "rs6951030".
> The command for doing this once that runs nicely is:
>
> RENAME VARS var002 = "rs"+ "6951030".
> EXE.
>
> Now I would like to do this for all vars through var3477.
> I have tried DO REPEAT and LOOP commands but they both say
> >Warning # 141.  Command name: RENAME VARS
> >DO REPEAT has no effect on this command.
>
> Any ideas on how I can do this (3477 times)?
>
> Thanks, Karen
>
Reply | Threaded
Open this post in threaded view
|

Re: RENAME LOOP?

King Douglas
In reply to this post by Raynald Levesque-2
Simple, parsimonious, beautiful.

King Douglas
American Airlines Customer Research

Raynald Levesque <[hidden email]> wrote: Hi Karen,

This is one way:

CD 'C:\temp'.

DATA LIST LIST /id var002 TO var006.
BEGIN DATA
9 2552 4215 4812 2400 65984
1 1 2 3 4 5
2 4 5 6 9 8
3 1 1 1 1 1
END DATA.
SAVE OUTFILE='original data.sav'.

GET FILE='original data.sav' /KEEP=var002 TO var006.
N OF CASES 1.
VECTOR v=var002 TO var006.
STRING newname(A18).
LOOP idx=2 TO 6.
- COMPUTE newname=CONCAT('var', LTRIM(STRING(v(idx - 1),F8))).
- FORMATS idx (N3).
- WRITE OUTFILE='syntax to rename.sps'
    /'RENAME VARIABLES (var', idx ,' = ', newname, ').'.
END LOOP.
EXECUTE.

GET FILE='original data.sav'.
INSERT FILE='syntax to rename.sps' .

Cheers!

Raynald Levesque
www.spsstools.net


On 7/25/07, Karen Powers  wrote:

>
> Hello SPSS list,
> I have a dataset in which the variable names are var002, var003   ...
> var3477.
>
> I would like to RENAME each variable with the number listed in row 1 of
> each respective column.
> The first number in var002 is 6951030.  I would like var002 renamed
> "rs6951030".
> The command for doing this once that runs nicely is:
>
> RENAME VARS var002 = "rs"+ "6951030".
> EXE.
>
> Now I would like to do this for all vars through var3477.
> I have tried DO REPEAT and LOOP commands but they both say
> >Warning # 141.  Command name: RENAME VARS
> >DO REPEAT has no effect on this command.
>
> Any ideas on how I can do this (3477 times)?
>
> Thanks, Karen
>
Reply | Threaded
Open this post in threaded view
|

Re: RENAME LOOP?

zstatman
What King said

W

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
King Douglas
Sent: Thursday, July 26, 2007 11:34 AM
To: [hidden email]
Subject: Re: RENAME LOOP?

Simple, parsimonious, beautiful.

King Douglas
American Airlines Customer Research

Raynald Levesque <[hidden email]> wrote: Hi Karen,

This is one way:

CD 'C:\temp'.

DATA LIST LIST /id var002 TO var006.
BEGIN DATA
9 2552 4215 4812 2400 65984
1 1 2 3 4 5
2 4 5 6 9 8
3 1 1 1 1 1
END DATA.
SAVE OUTFILE='original data.sav'.

GET FILE='original data.sav' /KEEP=var002 TO var006.
N OF CASES 1.
VECTOR v=var002 TO var006.
STRING newname(A18).
LOOP idx=2 TO 6.
- COMPUTE newname=CONCAT('var', LTRIM(STRING(v(idx - 1),F8))).
- FORMATS idx (N3).
- WRITE OUTFILE='syntax to rename.sps'
    /'RENAME VARIABLES (var', idx ,' = ', newname, ').'.
END LOOP.
EXECUTE.

GET FILE='original data.sav'.
INSERT FILE='syntax to rename.sps' .

Cheers!

Raynald Levesque
www.spsstools.net


On 7/25/07, Karen Powers  wrote:

>
> Hello SPSS list,
> I have a dataset in which the variable names are var002, var003   ...
> var3477.
>
> I would like to RENAME each variable with the number listed in row 1
> of each respective column.
> The first number in var002 is 6951030.  I would like var002 renamed
> "rs6951030".
> The command for doing this once that runs nicely is:
>
> RENAME VARS var002 = "rs"+ "6951030".
> EXE.
>
> Now I would like to do this for all vars through var3477.
> I have tried DO REPEAT and LOOP commands but they both say
> >Warning # 141.  Command name: RENAME VARS DO REPEAT has no effect on
> >this command.
>
> Any ideas on how I can do this (3477 times)?
>
> Thanks, Karen
>
Will
Statistical Services
 
============
info.statman@earthlink.net
http://home.earthlink.net/~z_statman/
============