changing string format according to another variable

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

changing string format according to another variable

Christopher Stride
Hi all
A looping question:

I have 600 string variables (say STR1 to STR600) for which I want to
change their length according to the contents of a set of 600 variables
(say LENG1 to LENG600)

e.g. for instance, if LENG3 = 'a40', I want to change the format of STR3
to (a40).

However it appears that
i) I can't use the alter type command within either do repeat loops or
loop loops.
ii) I can't create some new string vars to place the old values into
using vector, e.g.

vector l = STR1 to STR600 / g = LENG1 to LENG600 /k (600).
loop # = 1 to 600.
string k(#) g(#).
compute k(#) = l(#).
end loop.
exe.

doesn't work.

Any ideas for an elegant solution?

cheers
Chris




--

--

Dr Chris Stride, C. Stat, Statistician, Institute of Work Psychology,
University of Sheffield
Telephone: 0114 2223262
Fax: 0114 2727206

"Figure It Out"
Statistical Consultancy and Training Service for Social Scientists

Visit www.figureitout.org.uk for details of my consultancy services, and
forthcoming training courses, which are also available on an in-house basis:

  - Data management using SPSS syntax
  - Advanced SPSS syntax and SPSS macros
  - Testing for Mediation and Moderation using SPSS
  - Multi-level Modelling using SPSS
  - Introduction to Structural Equation Modelling using Mplus
  - Testing for Mediation and Moderation using Mplus
  - Multi-level Modelling using Mplus
  - Latent Growth Curve Modelling using Mplus

=====================
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: changing string format according to another variable

Jon K Peck
This would be easy to do using programmability, but first, two questions.

Would it suffice to just reduce each of the str variables to the minimum size to hold their current contents?  If so, using ALTER TYPE with AMIN as the output format would work.

For your LENG variables, since those are casewise, not scalars, are the values for all the cases the same?  Is just the first case sufficient here?


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




From:        Chris Stride <[hidden email]>
To:        [hidden email]
Date:        07/06/2015 06:20 AM
Subject:        [SPSSX-L] changing string format according to another variable
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hi all
A looping question:

I have 600 string variables (say STR1 to STR600) for which I want to
change their length according to the contents of a set of 600 variables
(say LENG1 to LENG600)

e.g. for instance, if LENG3 = 'a40', I want to change the format of STR3
to (a40).

However it appears that
i) I can't use the alter type command within either do repeat loops or
loop loops.
ii) I can't create some new string vars to place the old values into
using vector, e.g.

vector l = STR1 to STR600 / g = LENG1 to LENG600 /k (600).
loop # = 1 to 600.
string k(#) g(#).
compute k(#) = l(#).
end loop.
exe.

doesn't work.

Any ideas for an elegant solution?

cheers
Chris




--

--

Dr Chris Stride, C. Stat, Statistician, Institute of Work Psychology,
University of Sheffield
Telephone: 0114 2223262
Fax: 0114 2727206

"Figure It Out"
Statistical Consultancy and Training Service for Social Scientists

Visit
www.figureitout.org.uk for details of my consultancy services, and
forthcoming training courses, which are also available on an in-house basis:

 - Data management using SPSS syntax
 - Advanced SPSS syntax and SPSS macros
 - Testing for Mediation and Moderation using SPSS
 - Multi-level Modelling using SPSS
 - Introduction to Structural Equation Modelling using Mplus
 - Testing for Mediation and Moderation using Mplus
 - Multi-level Modelling using Mplus
 - Latent Growth Curve Modelling using Mplus

=====================
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
Reply | Threaded
Open this post in threaded view
|

Re: changing string format according to another variable

Christopher Stride
haha, values for all cases are not the same - but the alter type amin option combined with looping through cases using a v simple macro (I'm actually using spss to write html files, each row is a different file!)  nails it :)

Awesome, thanks... I'd not seen the amin option before, very neat...





On 06/07/2015 13:28, Jon K Peck wrote:
This would be easy to do using programmability, but first, two questions.

Would it suffice to just reduce each of the str variables to the minimum size to hold their current contents?  If so, using ALTER TYPE with AMIN as the output format would work.

For your LENG variables, since those are casewise, not scalars, are the values for all the cases the same?  Is just the first case sufficient here?


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




From:        Chris Stride [hidden email]
To:        [hidden email]
Date:        07/06/2015 06:20 AM
Subject:        [SPSSX-L] changing string format according to another variable
Sent by:        "SPSSX(r) Discussion" [hidden email]




Hi all
A looping question:

I have 600 string variables (say STR1 to STR600) for which I want to
change their length according to the contents of a set of 600 variables
(say LENG1 to LENG600)

e.g. for instance, if LENG3 = 'a40', I want to change the format of STR3
to (a40).

However it appears that
i) I can't use the alter type command within either do repeat loops or
loop loops.
ii) I can't create some new string vars to place the old values into
using vector, e.g.

vector l = STR1 to STR600 / g = LENG1 to LENG600 /k (600).
loop # = 1 to 600.
string k(#) g(#).
compute k(#) = l(#).
end loop.
exe.

doesn't work.

Any ideas for an elegant solution?

cheers
Chris




--

--

Dr Chris Stride, C. Stat, Statistician, Institute of Work Psychology,
University of Sheffield
Telephone: 0114 2223262
Fax: 0114 2727206

"Figure It Out"
Statistical Consultancy and Training Service for Social Scientists

Visit
www.figureitout.org.uk for details of my consultancy services, and
forthcoming training courses, which are also available on an in-house basis:

 - Data management using SPSS syntax
 - Advanced SPSS syntax and SPSS macros
 - Testing for Mediation and Moderation using SPSS
 - Multi-level Modelling using SPSS
 - Introduction to Structural Equation Modelling using Mplus
 - Testing for Mediation and Moderation using Mplus
 - Multi-level Modelling using Mplus
 - Latent Growth Curve Modelling using Mplus

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



-- 

--

Dr Chris Stride, C. Stat, Statistician, Institute of Work Psychology,
University of Sheffield
Telephone: 0114 2223262
Fax: 0114 2727206

"Figure It Out"
Statistical Consultancy and Training Service for Social Scientists

Visit www.figureitout.org.uk for details of my consultancy services, and
forthcoming training courses, which are also available on an in-house basis:

 - Data management using SPSS syntax
 - Advanced SPSS syntax and SPSS macros
 - Testing for Mediation and Moderation using SPSS
 - Multi-level Modelling using SPSS
 - Introduction to Structural Equation Modelling using Mplus
 - Testing for Mediation and Moderation using Mplus
 - Multi-level Modelling using Mplus
 - Latent Growth Curve Modelling using Mplus 
===================== 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