How to remove blank spaces from a string variable?

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

How to remove blank spaces from a string variable?

Justin Meyer-3
Hi SPSS list,

 

I would like to remove blank spaces from the front of a string variable.
The variable contains either one number (      123456) or a
number/letter combination (     a12345678b). The number varies from 1 to
10 digits long and the number of spaces also varies. Is there an
equivalent to Excel's TRIM function in SPSS or some other method I can
use to correct this? The numbers got this way when they were converted
from numeric to string so that the letters could be added, if that
helps.

 

Thank you,

____________________________________

Justin Meyer

Researcher

Rowland Reading Foundation

1 South Pinckney Street, Suite 324

Madison, WI  53703

phone: 866-370-7323  fax: 608-204-3846

www.rowlandreading.org <http://www.rowlandreading.org/>

____________________________________

====================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: How to remove blank spaces from a string variable?

ViAnn Beadle
The LTRIM function should do the trick here.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Justin Meyer
Sent: Tuesday, December 02, 2008 5:37 PM
To: [hidden email]
Subject: How to remove blank spaces from a string variable?

Hi SPSS list,



I would like to remove blank spaces from the front of a string variable.
The variable contains either one number (      123456) or a
number/letter combination (     a12345678b). The number varies from 1 to
10 digits long and the number of spaces also varies. Is there an
equivalent to Excel's TRIM function in SPSS or some other method I can
use to correct this? The numbers got this way when they were converted
from numeric to string so that the letters could be added, if that
helps.



Thank you,

____________________________________

Justin Meyer

Researcher

Rowland Reading Foundation

1 South Pinckney Street, Suite 324

Madison, WI  53703

phone: 866-370-7323  fax: 608-204-3846

www.rowlandreading.org <http://www.rowlandreading.org/>

____________________________________

=======
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: How to remove blank spaces from a string variable?

Justin Meyer-3
This for your help ViAnn.

I tried exactly this (where StudentID is the variable I want to trim):
LTRIM (StudentID).

And I got this:
LTRIM (StudentID).

>Error # 1.  Command name: LTRIM
>The first word in the line is not recognized as an SPSS command.
>This command not executed.

What am I missing? I think I have been at this too long today.
____________________________________

Justin Meyer

Rowland Reading Foundation

phone: 866-370-7323  fax: 608-204-3846

____________________________________


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
ViAnn Beadle
Sent: Tuesday, December 02, 2008 6:50 PM
To: [hidden email]
Subject: Re: How to remove blank spaces from a string variable?

The LTRIM function should do the trick here.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Justin Meyer
Sent: Tuesday, December 02, 2008 5:37 PM
To: [hidden email]
Subject: How to remove blank spaces from a string variable?

Hi SPSS list,



I would like to remove blank spaces from the front of a string variable.
The variable contains either one number (      123456) or a
number/letter combination (     a12345678b). The number varies from 1 to
10 digits long and the number of spaces also varies. Is there an
equivalent to Excel's TRIM function in SPSS or some other method I can
use to correct this? The numbers got this way when they were converted
from numeric to string so that the letters could be added, if that
helps.



Thank you,

____________________________________

Justin Meyer

Researcher

Rowland Reading Foundation

1 South Pinckney Street, Suite 324

Madison, WI  53703

phone: 866-370-7323  fax: 608-204-3846

www.rowlandreading.org <http://www.rowlandreading.org/>

____________________________________

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

Re: How to remove blank spaces from a string variable?

ViAnn Beadle
LTRIM is a function and not a command. Use it in a compute statement to
assign the value to a new variable. Go to help and search on string
functions for examples.

-----Original Message-----
From: Justin Meyer [mailto:[hidden email]]
Sent: Tuesday, December 02, 2008 6:00 PM
To: ViAnn Beadle; [hidden email]
Subject: RE: Re: How to remove blank spaces from a string variable?

This for your help ViAnn.

I tried exactly this (where StudentID is the variable I want to trim):
LTRIM (StudentID).

And I got this:
LTRIM (StudentID).

>Error # 1.  Command name: LTRIM
>The first word in the line is not recognized as an SPSS command.
>This command not executed.

What am I missing? I think I have been at this too long today.
____________________________________

Justin Meyer

Rowland Reading Foundation

phone: 866-370-7323  fax: 608-204-3846

____________________________________


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
ViAnn Beadle
Sent: Tuesday, December 02, 2008 6:50 PM
To: [hidden email]
Subject: Re: How to remove blank spaces from a string variable?

The LTRIM function should do the trick here.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Justin Meyer
Sent: Tuesday, December 02, 2008 5:37 PM
To: [hidden email]
Subject: How to remove blank spaces from a string variable?

Hi SPSS list,



I would like to remove blank spaces from the front of a string variable.
The variable contains either one number (      123456) or a
number/letter combination (     a12345678b). The number varies from 1 to
10 digits long and the number of spaces also varies. Is there an
equivalent to Excel's TRIM function in SPSS or some other method I can
use to correct this? The numbers got this way when they were converted
from numeric to string so that the letters could be added, if that
helps.



Thank you,

____________________________________

Justin Meyer

Researcher

Rowland Reading Foundation

1 South Pinckney Street, Suite 324

Madison, WI  53703

phone: 866-370-7323  fax: 608-204-3846

www.rowlandreading.org <http://www.rowlandreading.org/>

____________________________________

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

Re: How to remove blank spaces from a string variable?

Justin Meyer-3
LTRIM worked great! I used "Transform"-->"Compute Variable..." through
the GUI and I found out the you have to set the target variable to
string from the default numeric or you get an error. Once I figured that
out, it was easy. It's even better through the syntax.

Thanks ViAnn!

____________________________________

Justin Meyer

Rowland Reading Foundation

phone: 866-370-7323  fax: 608-204-3846

____________________________________

-----Original Message-----
From: ViAnn Beadle [mailto:[hidden email]]
Sent: Tuesday, December 02, 2008 7:09 PM
To: Justin Meyer; [hidden email]
Subject: RE: Re: How to remove blank spaces from a string variable?

LTRIM is a function and not a command. Use it in a compute statement to
assign the value to a new variable. Go to help and search on string
functions for examples.

-----Original Message-----
From: Justin Meyer [mailto:[hidden email]]
Sent: Tuesday, December 02, 2008 6:00 PM
To: ViAnn Beadle; [hidden email]
Subject: RE: Re: How to remove blank spaces from a string variable?

This for your help ViAnn.

I tried exactly this (where StudentID is the variable I want to trim):
LTRIM (StudentID).

And I got this:
LTRIM (StudentID).

>Error # 1.  Command name: LTRIM
>The first word in the line is not recognized as an SPSS command.
>This command not executed.

What am I missing? I think I have been at this too long today.
____________________________________

Justin Meyer

Rowland Reading Foundation

phone: 866-370-7323  fax: 608-204-3846

____________________________________


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
ViAnn Beadle
Sent: Tuesday, December 02, 2008 6:50 PM
To: [hidden email]
Subject: Re: How to remove blank spaces from a string variable?

The LTRIM function should do the trick here.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Justin Meyer
Sent: Tuesday, December 02, 2008 5:37 PM
To: [hidden email]
Subject: How to remove blank spaces from a string variable?

Hi SPSS list,



I would like to remove blank spaces from the front of a string variable.
The variable contains either one number (      123456) or a
number/letter combination (     a12345678b). The number varies from 1 to
10 digits long and the number of spaces also varies. Is there an
equivalent to Excel's TRIM function in SPSS or some other method I can
use to correct this? The numbers got this way when they were converted
from numeric to string so that the letters could be added, if that
helps.



Thank you,

____________________________________

Justin Meyer

Researcher

Rowland Reading Foundation

1 South Pinckney Street, Suite 324

Madison, WI  53703

phone: 866-370-7323  fax: 608-204-3846

www.rowlandreading.org <http://www.rowlandreading.org/>

____________________________________

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

Re: How to remove blank spaces from a string variable?

Paul Lachance
An example of syntax shows just how simple it is.  Assume a string variable NAME with some cases preceding by blank spaces.

COMPUTE NAME=LTRIM(NAME).
EXECUTE.