SPSS Loop Syntax to Rename Variables

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

SPSS Loop Syntax to Rename Variables

PsychGrad
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: SPSS Loop Syntax to Rename Variables

David Marso
Administrator
This is very unclear!  You need to better describe what you have and what you need and not depend upon our reading your mind!
PsychGrad wrote
All,

I've seen a lot of helpful posts using loops to rename a series of consecutive variables. However, I'm still stuck with my syntax.

Is there a clean way to use either 'Loop' or 'DO Repeat' to rename a series of variables?

In my case, I would like to rename 509 variables (var001 to var509) based on the Person#, Week, and Day that is listed in each variable column (e.g., var001 is person 2, week 1, day 2). As a result, I'd like var001 to become Person2Week1Day2.

Rather than writing a series of 'If' statements, I figured there's a more proficient way to accomplish this.

Any help would be much appreciated.

Sincerely,

Nick
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: SPSS Loop Syntax to Rename Variables

David Marso
Administrator
In reply to this post by PsychGrad
FYI & FWIW:
The following commands can be used within a DO REPEAT—END REPEAT structure:
• Data transformations: COMPUTE, RECODE, IF, COUNT, and SELECT IF
• Data declarations: VECTOR, STRING, NUMERIC, and LEAVE
• Data definition: DATA LIST, MISSING VALUES (but not VARIABLE LABELS or VALUE LABELS)
• Loop structure commands: LOOP, END LOOP, and BREAK
• Do-if structure commands: DO IF, ELSE IF, ELSE, and END IF
• Print and write commands: PRINT, PRINT EJECT, PRINT SPACE, and WRITE
• Format commands: PRINT FORMATS, WRITE FORMATS, and FORMATS

Similarily with LOOP
-----
You can *NOT* use values of variables to construct variable names within a RENAME without resorting to the *black arts*, python or scripting!
---
MACRO can construct such names within a !DO 'loop' but cannot readily access values of variables.
------------------------------
So where you came across several useful postings doing the basically impossible with SYNTAX is a matter of bemusement.
OTOH I am a master of the black arts!


PsychGrad wrote
- deleted -
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Automatic reply: SPSS Loop Syntax to Rename Variables

Muenchen, Robert A (Bob)

I'm out of the office until Monday June 18. While I'm out Mike O'Neil will be filling in for me. He's at 865-974-8333 or [hidden email].

 

Cheers, Bob

 

Reply | Threaded
Open this post in threaded view
|

Re: SPSS Loop Syntax to Rename Variables

PsychGrad
In reply to this post by PsychGrad
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: SPSS Loop Syntax to Rename Variables

Art Kendall
In reply to this post by PsychGrad
IIRC there is a python way to do this.  Here is a way that should work even with very old versions.
open a new syntax window.
paste and run the syntax below.
move to the output window.
highlight and copy the the block of text that was written.
another new syntax window.
type in without a period.
rename vars= var001 to var509 =
<paste the clipboard>
type in a period.

BTW the product of the loop maxima is not 509, you need to fix that.

new file.
input program.
string name1 to name7(a18).
vector name=name1 to name7.
   loop #per = 1 to 12.
      loop #wk = 1 to 6.
      loop #day = 1 to 7.
            compute name(#day) = concat(" Person", string(#per,n2), "Week", string(#wk,f1), "Day", string(#day,f1)).
         end loop.
         end case.
      end loop.
   end loop.
   end file.
end input program.


list variables = name1 to name7.
Art Kendall
Social Research Consultants

On 6/10/2012 11:22 AM, PsychGrad wrote:
All,

I've seen a lot of helpful posts using loops to rename a series of
consecutive variables. However, I'm still stuck with my syntax.

Is there a clean way to use either 'Loop' or 'DO Repeat' to rename a series
of variables?

In my case, I would like to rename 509 variables (var001 to var509) based on
the Person#, Week, and Day that is listed in each variable column (e.g.,
var001 is person 2, week 1, day 2). As a result, I'd like var001 to become
Person2Week1Day2.

Rather than writing a series of 'If' statements, I figured there's a more
proficient way to accomplish this.

Any help would be much appreciated.

Sincerely,

Nick

--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/SPSS-Loop-Syntax-to-Rename-Variables-tp5713615.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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

===================== 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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: SPSS Loop Syntax to Rename Variables

Jon K Peck
Art,

Clever, but it isn't clear to me whether the variable names are just indexed in the way this assumes or whether the values are supposed to come somehow from the data.

Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        Art Kendall <[hidden email]>
To:        [hidden email]
Date:        06/11/2012 05:37 AM
Subject:        Re: [SPSSX-L] SPSS Loop Syntax to Rename Variables
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




IIRC there is a python way to do this.  Here is a way that should work even with very old versions.
open a new syntax window.
paste and run the syntax below.
move to the output window.
highlight and copy the the block of text that was written.
another new syntax window.
type in without a period.

rename vars= var001 to var509 =

<paste the clipboard>
type in a period.

BTW the product of the loop maxima is not 509, you need to fix that.

new file.
input program.
string name1 to name7(a18).
vector name=name1 to name7.
  loop #per = 1 to 12.
     loop #wk = 1 to 6.
     loop #day = 1 to 7.
           compute name(#day) = concat(" Person", string(#per,n2), "Week", string(#wk,f1), "Day", string(#day,f1)).
        end loop.
        end case.
     end loop.
  end loop.
  end file.
end input program.


list variables = name1 to name7.

Art Kendall
Social Research Consultants


On 6/10/2012 11:22 AM, PsychGrad wrote:

All,

I've seen a lot of helpful posts using loops to rename a series of
consecutive variables. However, I'm still stuck with my syntax.

Is there a clean way to use either 'Loop' or 'DO Repeat' to rename a series
of variables?

In my case, I would like to rename 509 variables (var001 to var509) based on
the Person#, Week, and Day that is listed in each variable column (e.g.,
var001 is person 2, week 1, day 2). As a result, I'd like var001 to become
Person2Week1Day2.

Rather than writing a series of 'If' statements, I figured there's a more
proficient way to accomplish this.

Any help would be much appreciated.

Sincerely,

Nick

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/SPSS-Loop-Syntax-to-Rename-Variables-tp5713615.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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


===================== 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: SPSS Loop Syntax to Rename Variables

David Marso
Administrator
Precisely my point and cause for reticence in making any further effort.
Jon K Peck wrote
Art,

Clever, but it isn't clear to me whether the variable names are just
indexed in the way this assumes or whether the values are supposed to come
somehow from the data.

Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:   Art Kendall <[hidden email]>
To:     [hidden email]
Date:   06/11/2012 05:37 AM
Subject:        Re: [SPSSX-L] SPSS Loop Syntax to Rename Variables
Sent by:        "SPSSX(r) Discussion" <[hidden email]>



IIRC there is a python way to do this.  Here is a way that should work
even with very old versions.
open a new syntax window.
paste and run the syntax below.
move to the output window.
highlight and copy the the block of text that was written.
another new syntax window.
type in without a period.
rename vars= var001 to var509 =
<paste the clipboard>
type in a period.

BTW the product of the loop maxima is not 509, you need to fix that.

new file.
input program.
string name1 to name7(a18).
vector name=name1 to name7.
   loop #per = 1 to 12.
      loop #wk = 1 to 6.
      loop #day = 1 to 7.
            compute name(#day) = concat(" Person", string(#per,n2),
"Week", string(#wk,f1), "Day", string(#day,f1)).
         end loop.
         end case.
      end loop.
   end loop.
   end file.
end input program.

list variables = name1 to name7.
Art Kendall
Social Research Consultants

On 6/10/2012 11:22 AM, PsychGrad wrote:
All,

I've seen a lot of helpful posts using loops to rename a series of
consecutive variables. However, I'm still stuck with my syntax.

Is there a clean way to use either 'Loop' or 'DO Repeat' to rename a
series
of variables?

In my case, I would like to rename 509 variables (var001 to var509) based
on
the Person#, Week, and Day that is listed in each variable column (e.g.,
var001 is person 2, week 1, day 2). As a result, I'd like var001 to become
Person2Week1Day2.

Rather than writing a series of 'If' statements, I figured there's a more
proficient way to accomplish this.

Any help would be much appreciated.

Sincerely,

Nick

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/SPSS-Loop-Syntax-to-Rename-Variables-tp5713615.html

Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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


===================== 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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: SPSS Loop Syntax to Rename Variables

Art Kendall
In reply to this post by Jon K Peck
That is why I suggested the OP might need to change the loop indices. I made a swag from the post.
I just tried a combination of loop indices that came close to the giving 509 variables.
 
Art Kendall
Social Research Consultants

On 6/11/2012 9:23 AM, Jon K Peck wrote:
Art,

Clever, but it isn't clear to me whether the variable names are just indexed in the way this assumes or whether the values are supposed to come somehow from the data.

Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        Art Kendall [hidden email]
To:        [hidden email]
Date:        06/11/2012 05:37 AM
Subject:        Re: [SPSSX-L] SPSS Loop Syntax to Rename Variables
Sent by:        "SPSSX(r) Discussion" [hidden email]




IIRC there is a python way to do this.  Here is a way that should work even with very old versions.
open a new syntax window.
paste and run the syntax below.
move to the output window.
highlight and copy the the block of text that was written.
another new syntax window.
type in without a period.

rename vars= var001 to var509 =

<paste the clipboard>
type in a period.

BTW the product of the loop maxima is not 509, you need to fix that.

new file.
input program.
string name1 to name7(a18).
vector name=name1 to name7.
  loop #per = 1 to 12.
     loop #wk = 1 to 6.
     loop #day = 1 to 7.
           compute name(#day) = concat(" Person", string(#per,n2), "Week", string(#wk,f1), "Day", string(#day,f1)).
        end loop.
        end case.
     end loop.
  end loop.
  end file.
end input program.


list variables = name1 to name7.

Art Kendall
Social Research Consultants


On 6/10/2012 11:22 AM, PsychGrad wrote:

All,

I've seen a lot of helpful posts using loops to rename a series of
consecutive variables. However, I'm still stuck with my syntax.

Is there a clean way to use either 'Loop' or 'DO Repeat' to rename a series
of variables?

In my case, I would like to rename 509 variables (var001 to var509) based on
the Person#, Week, and Day that is listed in each variable column (e.g.,
var001 is person 2, week 1, day 2). As a result, I'd like var001 to become
Person2Week1Day2.

Rather than writing a series of 'If' statements, I figured there's a more
proficient way to accomplish this.

Any help would be much appreciated.

Sincerely,

Nick

--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/SPSS-Loop-Syntax-to-Rename-Variables-tp5713615.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
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


===================== 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
===================== 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
Art Kendall
Social Research Consultants