changing width of strings

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

changing width of strings

Cleland, Patricia (EDU)

I’m trying to merge the results of two versions of a questionnaire but I’m having problems with some of the open-ended questions.  For example, in one of the versions, the format of a variable is A22 and in the other version it’s A36.  I assume that if I change the format in the first version to A36, the merge should work.  I can certainly go in and do that by hand, but that’s labour intensive, error prone, doesn’t leave an audit trail and requires stopping in the middle of a run. 

 

When I had a similar problem with a variable that should have been numeric in both versions but came through as a string in one version, I used the COMPUTE NewVar=numeric(OldVar, F6) command. 

 

Is there something similar that I can use for strings?

 

TIA

Pat

Reply | Threaded
Open this post in threaded view
|

Re: changing width of strings

Maguin, Eugene
Patricia, look at the Alter type command. Extremely useful. Gene Maguin


From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Cleland, Patricia (EDU)
Sent: Wednesday, July 21, 2010 9:25 AM
To: [hidden email]
Subject: changing width of strings

I’m trying to merge the results of two versions of a questionnaire but I’m having problems with some of the open-ended questions.  For example, in one of the versions, the format of a variable is A22 and in the other version it’s A36.  I assume that if I change the format in the first version to A36, the merge should work.  I can certainly go in and do that by hand, but that’s labour intensive, error prone, doesn’t leave an audit trail and requires stopping in the middle of a run. 

 

When I had a similar problem with a variable that should have been numeric in both versions but came through as a string in one version, I used the COMPUTE NewVar=numeric(OldVar, F6) command. 

 

Is there something similar that I can use for strings?

 

TIA

Pat

Reply | Threaded
Open this post in threaded view
|

Re: changing width of strings

Vlad Lopez
Any idea how to ALTER TYPE using old SPSS versions, such as 13?
 
vlad

On Wed, Jul 21, 2010 at 6:34 AM, Gene Maguin <[hidden email]> wrote:
Patricia, look at the Alter type command. Extremely useful. Gene Maguin


From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Cleland, Patricia (EDU)
Sent: Wednesday, July 21, 2010 9:25 AM
To: [hidden email]
Subject: changing width of strings

I’m trying to merge the results of two versions of a questionnaire but I’m having problems with some of the open-ended questions.  For example, in one of the versions, the format of a variable is A22 and in the other version it’s A36.  I assume that if I change the format in the first version to A36, the merge should work.  I can certainly go in and do that by hand, but that’s labour intensive, error prone, doesn’t leave an audit trail and requires stopping in the middle of a run. 

 

When I had a similar problem with a variable that should have been numeric in both versions but came through as a string in one version, I used the COMPUTE NewVar=numeric(OldVar, F6) command. 

 

Is there something similar that I can use for strings?

 

TIA

Pat


Reply | Threaded
Open this post in threaded view
|

Re: changing width of strings

Jon K Peck
In reply to this post by Cleland, Patricia (EDU)

The way to do this is with the ALTER TYPE command.  It can change string widths as well as things like changing between string and numeric (subject to data conversion).

You can do this without necessarily having to name the variables.  For example, you could use the command to change all A22 variables to A36 variables like this.

alter type ALL(A22=A36).

The variable list, ALL in this example, is filtered by the format specification, and the new specification is assigned.

The form varlist(format)  i.,e., without the =, just changes all the listed variables to the specified format.

The default output produces a table of what was changed.

HTH,

Jon Peck
(designer of ALTER TYPE)

SPSS, an IBM Company
[hidden email]
312-651-3435



From: "Cleland, Patricia (EDU)" <[hidden email]>
To: [hidden email]
Date: 07/21/2010 07:26 AM
Subject: [SPSSX-L] changing width of strings
Sent by: "SPSSX(r) Discussion" <[hidden email]>





I’m trying to merge the results of two versions of a questionnaire but I’m having problems with some of the open-ended questions.  For example, in one of the versions, the format of a variable is A22 and in the other version it’s A36.  I assume that if I change the format in the first version to A36, the merge should work.  I can certainly go in and do that by hand, but that’s labour intensive, error prone, doesn’t leave an audit trail and requires stopping in the middle of a run.  
 
When I had a similar problem with a variable that should have been numeric in both versions but came through as a string in one version, I used the COMPUTE NewVar=numeric(OldVar, F6) command.  
 
Is there something similar that I can use for strings?
 

TIA

Pat

Reply | Threaded
Open this post in threaded view
|

Re: changing width of strings

Bruce Weaver
Administrator
In reply to this post by Vlad Lopez
Vladimir Lopez-Prado wrote
Any idea how to ALTER TYPE using old SPSS versions, such as 13?

vlad
Suppose MYSTRING is the string variable you want to change from A22 to A36.

rename variables (mystring = junk).
string mystring (a36).
compute mystring = junk.
exe.

* Throw out the junk -- assuming DELETE VARIABLES is not available .

match files file = * / drop = junk.
exe.

--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
Reply | Threaded
Open this post in threaded view
|

Re: changing width of strings

Maguin, Eugene
In reply to this post by Vlad Lopez
Vlad,

Alter type was added in 16. I don't know of any method for pre-16 version.
Probably a macro could be written but others are more knowledgable about
this. I think the key problem is that you need to know the maximum length of
the text in the variable.

Gene Maguin



________________________________

From: Vladimir Lopez-Prado [mailto:[hidden email]]
Sent: Wednesday, July 21, 2010 9:53 AM
To: Gene Maguin
Cc: [hidden email]
Subject: Re: changing width of strings


Any idea how to ALTER TYPE using old SPSS versions, such as 13?

vlad


On Wed, Jul 21, 2010 at 6:34 AM, Gene Maguin <[hidden email]> wrote:


        Patricia, look at the Alter type command. Extremely useful. Gene
Maguin

________________________________

        From: SPSSX(r) Discussion [mailto:[hidden email]] On
Behalf Of Cleland, Patricia (EDU)
        Sent: Wednesday, July 21, 2010 9:25 AM
        To: [hidden email]
        Subject: changing width of strings



        I'm trying to merge the results of two versions of a questionnaire
but I'm having problems with some of the open-ended questions.  For example,
in one of the versions, the format of a variable is A22 and in the other
version it's A36.  I assume that if I change the format in the first version
to A36, the merge should work.  I can certainly go in and do that by hand,
but that's labour intensive, error prone, doesn't leave an audit trail and
requires stopping in the middle of a run.



        When I had a similar problem with a variable that should have been
numeric in both versions but came through as a string in one version, I used
the COMPUTE NewVar=numeric(OldVar, F6) command.



        Is there something similar that I can use for strings?



        TIA

        Pat

=====================
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 width of strings

Cleland, Patricia (EDU)
In reply to this post by Maguin, Eugene

Thanks. That does exactly what I want.

 

Pat

--------------------------------
Patricia Cleland, OCT
Senior Statistical and Research Analyst
Learning Environment Branch
Ministry of Education

15th Floor, Mowat Block
900 Bay Street
Toronto, Ontario
M7A 1L2

phone: 416-325-2697
fax:     416-325-4344

email: [hidden email]


From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Gene Maguin
Sent: July 21, 2010 9:34 AM
To: [hidden email]
Subject: Re: [SPSSX-L] changing width of strings

 

Patricia, look at the Alter type command. Extremely useful. Gene Maguin

 


From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Cleland, Patricia (EDU)
Sent: Wednesday, July 21, 2010 9:25 AM
To: [hidden email]
Subject: changing width of strings

I’m trying to merge the results of two versions of a questionnaire but I’m having problems with some of the open-ended questions.  For example, in one of the versions, the format of a variable is A22 and in the other version it’s A36.  I assume that if I change the format in the first version to A36, the merge should work.  I can certainly go in and do that by hand, but that’s labour intensive, error prone, doesn’t leave an audit trail and requires stopping in the middle of a run. 

 

When I had a similar problem with a variable that should have been numeric in both versions but came through as a string in one version, I used the COMPUTE NewVar=numeric(OldVar, F6) command. 

 

Is there something similar that I can use for strings?

 

TIA

Pat

Reply | Threaded
Open this post in threaded view
|

Re: changing width of strings

Ruben Geert van den Berg
In reply to this post by Maguin, Eugene
For the sake of the exercise, I wrote a small Python program that sets all string lengths to an arbitrary length (e.g. a1000) without alter type (in case you work with version 15 or earlier). It preserves variable labels but not value labels (which are often absent with strings anyway). I think it also preserves the original order of variables in the file. In the unlikely case anyone would like to try it, I can look it up, retest it and mail it.

Some Python code that sets all string variables to their minimally required lengths across data files would come in handy as well, I'll give it a try if I'll find the time.

Another useful tool would be code that checks the dictionary information of numeric variables across files and identifies those variables (if any) for which this is inconsistent. ADD FILES won't generate any warning/error in this case. I previously used OMS -> display dictionary -> casestovars -> compute identifier = not (label_1=label_2=...) for this. This will work but the resulting syntax was rather clumsy.

Best,

Ruben van den Berg
Consultant Models & Methods
TNS NIPO
Email: [hidden email]
Mobiel: +31 6 24641435
Telefoon: +31 20 522 5738
Internet: www.tns-nipo.com




> Date: Wed, 21 Jul 2010 10:12:10 -0400
> From: [hidden email]
> Subject: Re: changing width of strings
> To: [hidden email]
>
> Vlad,
>
> Alter type was added in 16. I don't know of any method for pre-16 version.
> Probably a macro could be written but others are more knowledgable about
> this. I think the key problem is that you need to know the maximum length of
> the text in the variable.
>
> Gene Maguin
>
>
>
> ________________________________
>
> From: Vladimir Lopez-Prado [mailto:[hidden email]]
> Sent: Wednesday, July 21, 2010 9:53 AM
> To: Gene Maguin
> Cc: [hidden email]
> Subject: Re: changing width of strings
>
>
> Any idea how to ALTER TYPE using old SPSS versions, such as 13?
>
> vlad
>
>
> On Wed, Jul 21, 2010 at 6:34 AM, Gene Maguin <[hidden email]> wrote:
>
>
> Patricia, look at the Alter type command. Extremely useful. Gene
> Maguin
>
> ________________________________
>
> From: SPSSX(r) Discussion [mailto:[hidden email]] On
> Behalf Of Cleland, Patricia (EDU)
> Sent: Wednesday, July 21, 2010 9:25 AM
> To: [hidden email]
> Subject: changing width of strings
>
>
>
> I'm trying to merge the results of two versions of a questionnaire
> but I'm having problems with some of the open-ended questions. For example,
> in one of the versions, the format of a variable is A22 and in the other
> version it's A36. I assume that if I change the format in the first version
> to A36, the merge should work. I can certainly go in and do that by hand,
> but that's labour intensive, error prone, doesn't leave an audit trail and
> requires stopping in the middle of a run.
>
>
>
> When I had a similar problem with a variable that should have been
> numeric in both versions but came through as a string in one version, I used
> the COMPUTE NewVar=numeric(OldVar, F6) command.
>
>
>
> Is there something similar that I can use for strings?
>
>
>
> TIA
>
> Pat
>
> =====================
> 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


New Windows 7: Find the right PC for you. Learn more.
Reply | Threaded
Open this post in threaded view
|

Re: changing width of strings

Bruce Weaver
Administrator
Ruben van den Berg wrote
For the sake of the exercise, I wrote a small Python program that sets all string lengths to an arbitrary length (e.g. a1000) without alter type (in case you work with version 15 or earlier).
Or in other words (if I'm not mistaken), if you work with version 14 or 15.  Python programmability only appeared in v14, didn't it?  

--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.
Reply | Threaded
Open this post in threaded view
|

Re: changing width of strings

SUMAN SEN
In reply to this post by Ruben Geert van den Berg
Hi Ruben,
"Some Python code that sets all string variables to their minimally required lengths across data files would come in handy as well, I'll give it a try if I'll find the time." - Any progress on this apart from the syntax that you have shared in SPSS tutorials as I am getting some error while running that. I have checked that python is running properly in SPSS.

In my case, I am handling multiple data file with approximately more than 1K variable in each data file and I don't want to use Alter type as it is a time taking and painful task.
Reply | Threaded
Open this post in threaded view
|

Re: changing width of strings

Jon Peck
ALTER TYPE can do this.  No Python is required.  E.g.,  
ALTER TYPE ALL (A=AMIN).

On Mon, Nov 21, 2016 at 10:50 PM, SUMAN SEN <[hidden email]> wrote:
Hi Ruben,
"Some Python code that sets all string variables to their minimally required
lengths across data files would come in handy as well, I'll give it a try if
I'll find the time." - Any progress on this apart from the syntax that you
have shared in SPSS tutorials as I am getting some error while running that.
I have checked that python is running properly in SPSS.

In my case, I am handling multiple data file with approximately more than 1K
variable in each data file and I don't want to use Alter type as it is a
time taking and painful task.



--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/changing-width-of-strings-tp1718480p5733498.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



--
Jon K Peck
[hidden email]

===================== 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 width of strings

SUMAN SEN
Thanks Jon Peck for the reply.

Actually I have 7 SPSS data files, each having around more than 1000 numeric variables with
one Lakh records in each file. I have to merge all this 7 files. While I am using ALTER TYPE ALL(A=AMIN), it is taking almost more than 30 mins to convert to string variables and whole day to save the file, which is not convenient in our daily process. Could you please suggest something else which will easy to get the String SPSS file with actual width (to reduce the file size) and save our time.

Here is my code that I am using.

DO REPEAT varlist= Var1 to Var500 Var515 to Var801 Var805 to Var1000. # Spliting Variable list to exculde numerical variable.
/newvars=S1 to S500 S515 to S801 S805 to S1000.
- STRING newvars(A360).
- COMPUTE newvars=VALUELABEL(varlist).
END REPEAT.

DELETE VARIABLES =Var1 to Var500 Var515 to Var801 Var805 to Var1000. # Deleting Numerical Variable as we need only string Variables.

ALTER TYPE ALL(A=Amin).

SAVE OUTFILE="C:\XXXX\Desktop\XXXX.sav"
/COMPRESSED.

If I run this above code it is taking time as I mentioned above.  Once I get the solution for this, I can adjust the width to merge the files as Width should be same across all the string files for merging in SPSS. Please let me know if you have any question.

Thank you very mush for all your help in advance.
It would be a great help if I get the solution for Thank you in advance.
Reply | Threaded
Open this post in threaded view
|

Re: changing width of strings

Jon Peck
Those times seem quite excessive unless your hardware is very slow or memory is severely limited.  (I believe one lakh is 100,000, correct?).  I don't know where the excess time is spent, but here are some suggestions that might help.

1.  This is not a performance issue but rather a maintainability issue.  You have spelled out the numeric variables explicitly.  If this might change, I suggest using the SPSSINC SELECT VARIABLES (Utilities > Define Variable) extension command to generate a macro listing all the numeric variables so that your code need not change if the list or order of the variables does.  Then use the macro in place of the lists of numeric variables.  If this command is not already installed on your system, use the Utilities menu (Extensions in V24) to install it.  A small bit of Python code, which I will write if you want to go this route, could generate the corresponding S variables. 

2.  Declare all the new string variables in a single STRING command before the DO REPEAT loop.

3.  Set the width in the STRING command to 255.  That is the maximum length of a value label, and allocating more than 255 bytes to a string variable has some extra overhead beyond just the extra space consumed.

It is unusual to need to convert labelled numeric values to strings, so if you can explain the context, perhaps this entire step could be avoided.  Note also that merging string variables requires that they be the same width.  This process would not guarantee that.  Perhaps the merge should happen first.  The STATS ADJUST WIDTHS extension command can rationalize the widths across files, but it would introduce extra processing time into the process.

If these suggestions don't help and you want to send me a sample file, I can look further at it.


On Tue, Nov 22, 2016 at 11:25 PM, SUMAN SEN <[hidden email]> wrote:
Thanks Jon Peck for the reply.

Actually I have 7 SPSS data files, each having around more than 1000 numeric
variables with
one Lakh records in each file. I have to merge all this 7 files. While I am
using ALTER TYPE ALL(A=AMIN), it is taking almost more than 30 mins to
convert to string variables and whole day to save the file, which is not
convenient in our daily process. Could you please suggest something else
which will easy to get the String SPSS file with actual width (to reduce the
file size) and save our time.

Here is my code that I am using.

DO REPEAT varlist= Var1 to Var500 Var515 to Var801 Var805 to Var1000. #
Spliting Variable list to exculde numerical variable.
/newvars=S1 to S500 S515 to S801 S805 to S1000.
- STRING newvars(A360).
- COMPUTE newvars=VALUELABEL(varlist).
END REPEAT.

DELETE VARIABLES =Var1 to Var500 Var515 to Var801 Var805 to Var1000. #
Deleting Numerical Variable as we need only string Variables.

ALTER TYPE ALL(A=Amin).

SAVE OUTFILE="C:\XXXX\Desktop\XXXX.sav"
/COMPRESSED.

If I run this above code it is taking time as I mentioned above.  Once I get
the solution for this, I can adjust the width to merge the files as Width
should be same across all the string files for merging in SPSS. Please let
me know if you have any question.

Thank you very mush for all your help in advance.
It would be a great help if I get the solution for Thank you in advance.



--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/changing-width-of-strings-tp1718480p5733503.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



--
Jon K Peck
[hidden email]

===================== 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 width of strings

SUMAN SEN
Thanks a lot Jon Peck for your reply.

Let me answer your question first
1) "One lakh is 100,000, correct?" - Yes,you are correct. and we are using SPSS 23.
2) "A small bit of Python code, which I will write if you want to go this route, could generate the corresponding S variable" - It will be great help for me if you please provide that python code.
3) "It is unusual to need to convert labelled numeric values to strings," - as we have different project  wise data file which need to merge to get a consolidated file. Variable and corresponding value labels are not consistent across the project data (having some common variable and also some new variable). Hence we are merging by using string method. Below is the code that I am using for your reference :

DO REPEAT varlist= AGE EMPID JOBD EDUD GENDER INCOME REGION LOCAT COUNTRY YEAR. #
Spliting Variable list to exculde numerical variable.

/newvars=AGE_str EMPID_str JOBD_str EDUD_str GENDER_str INCOME_str REGION_str LOCAT_str COUNTRY_str YEAR_str.
- STRING newvars(A255).
- COMPUTE newvars=VALUELABEL(varlist).
END REPEAT.

DELETE VARIABLES =AGE EMPID JOBD EDUD GENDER INCOME REGION LOCAT COUNTRY YEAR. #
Deleting Numerical Variable as we need only string Variables.

SAVE OUTFILE="C:\XXXX\Desktop\XXXX.sav"
/COMPRESSED.

4) "Declare all the new string variables in a single STRING command before the DO REPEAT loop." - I have tried this but as we have different variable
name (not like V1 to V10 convert S1 to S10), hence the code is not working if I keep that out side of the loop.

Please suggest the best solution. Thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: changing width of strings

SUMAN SEN
In reply to this post by Jon Peck
Following with above post, I have another question.
It is taking time to save the string file and also running CTABLES (like 5/6hrs) for 9000+ Variables.
It will be a great help if you suggest something better to solve the this point as well.

Thanks & regards,
Suman Sen
Reply | Threaded
Open this post in threaded view
|

Re: changing width of strings

David Marso
Administrator
In reply to this post by SUMAN SEN
" as we have different project  wise data file which need to merge to get a consolidated file. Variable and corresponding value labels are not consistent across the project data (having some common variable and also some new variable). Hence we are merging by using string method. Below is the code that I am using for your reference : "

I have NO idea what this means or why it is relevant to merging files with what you say are NUMERIC data.
This sounds like a complete Flustercluck driven by RCI.  Back up several steps and lay out a specific example of what/why things are all screwed up?  Is it the case that variables with the same name in different files represent different substantive elements?  If the variable/value labels don't match then what do you gain by digging the hole deeper?

"Hence we are merging by using string method. "
Now you have really lost me.  Best solution for your unit is to hire a competent data manager.
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?"