Changing the number of characters in string variable

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

Changing the number of characters in string variable

Jeff A

 

I can’t seem to find the answer to a seemingly simple question.

 

Can I easily change the number of characters in a string variable or do I have to create a new string, convert the old to the new, and then delete the original?

 

Best,

 

Jeff

 

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

Never mind - Changing the number of characters in string variable

Jeff A

 

…just found Alter Type.

 

 

===================== 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: Never mind - Changing the number of characters in string variable

Jeff A

 

 

Thanks for this. I never would have thought that this would have been built into the syntax.

 

It’s exactly what I need since I am merging two different datasets, where one is being periodically updated by automated survey software after additional on-line surveys are completed and placed into the newer of the two datasets. A selected number of string variables in the newer dataset get their lengths automatically increased by the survey software if a respondent types in a long response. This subsequently then won’t match the length of the variables in the other dataset that’s already completed. I was just planning to go back and alter my merge syntax if this occurred and drew an error, but using the A=Amin format will keep the string lengths as short as possible without me having to correct the syntax periodically.

 

Best,

 

Jeff

 

 

Sent: Friday, August 9, 2019 3:49 AM
To: Jeff <[hidden email]>
Subject: Re: Never mind - Changing the number of characters in string variable

 

FYI a nice trick is:

 

alter type all (A=Amin).

*which sets all strings to the min necessary.

 

* for merging files where the strings need to be the same length, I’ll quickly determine the max string length in either file, use (example 500 is nice and large to include everything):

*for each file do:.

alter type all (A=A500).

*add the files then run: .

alter type all (A=Amin).

 

 

 

Kathy Reinig
KJ Reinig Associates
quantitative research analysts


On Aug 8, 2019, at 2:15 AM, Jeff <[hidden email]> wrote:

 

 

…just found Alter Type.

 

 

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

 


Virus-free. www.avast.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: Never mind - Changing the number of characters in string variable

Jon Peck
You might want to incorporate the STATS ADJUST WIDTHS extension command into your syntax.  It takes file wildcard specifying a set of files and automatically synchronizes the string widths according to one of several rules.  (It actually uses ALTER TYPE under the covers).

On Thu, Aug 8, 2019 at 3:47 PM Jeff A <[hidden email]> wrote:

 

 

Thanks for this. I never would have thought that this would have been built into the syntax.

 

It’s exactly what I need since I am merging two different datasets, where one is being periodically updated by automated survey software after additional on-line surveys are completed and placed into the newer of the two datasets. A selected number of string variables in the newer dataset get their lengths automatically increased by the survey software if a respondent types in a long response. This subsequently then won’t match the length of the variables in the other dataset that’s already completed. I was just planning to go back and alter my merge syntax if this occurred and drew an error, but using the A=Amin format will keep the string lengths as short as possible without me having to correct the syntax periodically.

 

Best,

 

Jeff

 

 

Sent: Friday, August 9, 2019 3:49 AM
To: Jeff <[hidden email]>
Subject: Re: Never mind - Changing the number of characters in string variable

 

FYI a nice trick is:

 

alter type all (A=Amin).

*which sets all strings to the min necessary.

 

* for merging files where the strings need to be the same length, I’ll quickly determine the max string length in either file, use (example 500 is nice and large to include everything):

*for each file do:.

alter type all (A=A500).

*add the files then run: .

alter type all (A=Amin).

 

 

 

Kathy Reinig
KJ Reinig Associates
quantitative research analysts


On Aug 8, 2019, at 2:15 AM, Jeff <[hidden email]> wrote:

 

 

…just found Alter Type.

 

 

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

 


Virus-free. www.avast.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: Never mind - Changing the number of characters in string variable

Jon Peck
In reply to this post by Jeff A
You can specify a variable list with STATS ADJUST  WIDTH, but the point of using it was to automate the adjustment and eliminate the need to generate an error and then manually go back and fix the variable(s).  

And since ALTER TYPE, much as I like it (I designed it), works on one file at a time, so A=AMIN isn't guaranteed to synchronize the widths across files/datasets.

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