Creation of New Groups of variables that correspond to the old groups

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

Creation of New Groups of variables that correspond to the old groups

georgeb
I have a long set of variables, titled SU1a, SU1b, SU1c, SU1d, SU1e all the way through SU40a, SU40b etc.  I am trying to create new variables with a similar naming scheme, but with "_p" added to the end.  Further, I need to put the groupings of variables next to each corresponding group, i.e. SU1a, SU1b, SU1c, SU1d, SU1e, SU1a_p, SU1b_p, SU1c_p, SU1d_p, SU1e_p, SU2a, SU2b...

I could grunt my way through this and create them by hand, or write the syntax for every variable, but it seems like I should be able to create a looping function or a macro that uses "SU1" or "SU2" etc as a starting point for creation, correct naming, and relocating the new variables. The things I have tried so far have not gotten me anywhere.

Any ideas?
Reply | Threaded
Open this post in threaded view
|

Re: Creation of New Groups of variables that correspond to the old groups

John F Hall

George

 

You can use DO REPEAT for existing vars, but you need to generate the new var names yourself if you want to stick _p on the end of each name.  SPSS can't automatically generate new vars ending in alpha characters Other listers will show you how to do this.

 

do repeat

      x = su1a to su40e

      /y = <new var lis>

compute y = x.

end repeat.

sort variables by name.

 

The grunty way would be:

 

do repeat

      x = su1a to su40e

      /y = su1a_p su1b_p  ~ ~ ~ ~

            ~ ~ ~ su40d_p su40e_p.

compute y = x.

end repeat.

*Never used this, but it should work.

sort variables by name.

 

. . . but the syntax gurus will come up with something more elegant for the new names and also to sort into the order you want. 

 

 

John F Hall (Mr)

[retired academic survey researcher]

 

Email:     [hidden email]

Website: www.surveyresearch.weebly.com

 

 

 

 

 

 

 

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of georgeb
Sent: 08 March 2013 17:27
To: [hidden email]
Subject: Creation of New Groups of variables that correspond to the old groups

 

I have a long set of variables, titled SU1a, SU1b, SU1c, SU1d, SU1e all the way through SU40a, SU40b etc.  I am trying to create new variables with a similar naming scheme, but with "_p" added to the end.  Further, I need to put the groupings of variables next to each corresponding group, i.e. SU1a, SU1b, SU1c, SU1d, SU1e, SU1a_p, SU1b_p, SU1c_p, SU1d_p, SU1e_p, SU2a, SU2b...

 

I could grunt my way through this and create them by hand, or write the syntax for every variable, but it seems like I should be able to create a looping function or a macro that uses "SU1" or "SU2" etc as a starting point for creation, correct naming, and relocating the new variables. The things I have tried so far have not gotten me anywhere.

 

Any ideas?

 

 

 

--

View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Creation-of-New-Groups-of-variables-that-correspond-to-the-old-groups-tp5718485.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

Reply | Threaded
Open this post in threaded view
|

Re: Creation of New Groups of variables that correspond to the old groups

David Marso
Administrator
This post was updated on .
In reply to this post by georgeb
SEE:
DEFINE !ENDDEFINE (!DO) and NUMERIC commands.
Edit:  Also SORT VARIABLES command.
--
georgeb wrote
I have a long set of variables, titled SU1a, SU1b, SU1c, SU1d, SU1e all the way through SU40a, SU40b etc.  I am trying to create new variables with a similar naming scheme, but with "_p" added to the end.  Further, I need to put the groupings of variables next to each corresponding group, i.e. SU1a, SU1b, SU1c, SU1d, SU1e, SU1a_p, SU1b_p, SU1c_p, SU1d_p, SU1e_p, SU2a, SU2b...

I could grunt my way through this and create them by hand, or write the syntax for every variable, but it seems like I should be able to create a looping function or a macro that uses "SU1" or "SU2" etc as a starting point for creation, correct naming, and relocating the new variables. The things I have tried so far have not gotten me anywhere.

Any ideas?
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: Creation of New Groups of variables that correspond to the old groups

Art Kendall
In reply to this post by georgeb
Perhaps next project you might use a different naming scheme.   Prefixes are often easier to program with than suffixes.


take a look at SORT Variables.
Art Kendall
Social Research Consultants
On 3/8/2013 11:26 AM, georgeb wrote:
I have a long set of variables, titled SU1a, SU1b, SU1c, SU1d, SU1e all the
way through SU40a, SU40b etc.  I am trying to create new variables with a
similar naming scheme, but with "_p" added to the end.  Further, I need to
put the groupings of variables next to each corresponding group, i.e. SU1a,
SU1b, SU1c, SU1d, SU1e, SU1a_p, SU1b_p, SU1c_p, SU1d_p, SU1e_p, SU2a,
SU2b...

I could grunt my way through this and create them by hand, or write the
syntax for every variable, but it seems like I should be able to create a
looping function or a macro that uses "SU1" or "SU2" etc as a starting point
for creation, correct naming, and relocating the new variables. The things I
have tried so far have not gotten me anywhere.

Any ideas?



--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Creation-of-New-Groups-of-variables-that-correspond-to-the-old-groups-tp5718485.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: Creation of New Groups of variables that correspond to the old groups

Albert-Jan Roskam
import spssaux, spss
vars = spssaux.VariableDict(pattern="SU[0-9]+[a-z]").variables
spss.Submit(["numeric %s (f5)." % (var + "_p") for var in vars])
vars = sorted(spssaux.VariableDict(pattern="SU[0-9]+[a-z](_p)?").variables)
spss.Submit("add files /file = * /keep = %s." % " ".join(vars))
 
Regards,
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a
fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

From: Art Kendall <[hidden email]>
To: [hidden email]
Sent: Saturday, March 9, 2013 2:33 PM
Subject: Re: [SPSSX-L] Creation of New Groups of variables that correspond to the old groups

Perhaps next project you might use a different naming scheme.   Prefixes are often easier to program with than suffixes.


take a look at SORT Variables.
Art Kendall
Social Research Consultants
On 3/8/2013 11:26 AM, georgeb wrote:
I have a long set of variables, titled SU1a, SU1b, SU1c, SU1d, SU1e all the
way through SU40a, SU40b etc.  I am trying to create new variables with a
similar naming scheme, but with "_p" added to the end.  Further, I need to
put the groupings of variables next to each corresponding group, i.e. SU1a,
SU1b, SU1c, SU1d, SU1e, SU1a_p, SU1b_p, SU1c_p, SU1d_p, SU1e_p, SU2a,
SU2b...

I could grunt my way through this and create them by hand, or write the
syntax for every variable, but it seems like I should be able to create a
looping function or a macro that uses "SU1" or "SU2" etc as a starting point
for creation, correct naming, and relocating the new variables. The things I
have tried so far have not gotten me anywhere.

Any ideas?



--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Creation-of-New-Groups-of-variables-that-correspond-to-the-old-groups-tp5718485.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