Trim Right And Left Blank Spaces

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

Trim Right And Left Blank Spaces

mcgannmary
Hi,

I'm working with variables that are alphanumeric and look like this, for
example:
Diagnosis Code
     A123
938512
 48300007

I need to remove the leading and trailing white space and have tried
everything I can find in previous discussions, but nothing is working.

Any help would be appreciated.

Thank you!
Mary




--
Sent from: http://spssx-discussion.1045642.n5.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: Trim Right And Left Blank Spaces

Maguin, Eugene
Look at the ltrim and rtrim character functions.

X = ltrim(rtrim(x))

Gene Maguin

-----Original Message-----
From: SPSSX(r) Discussion <[hidden email]> On Behalf Of mcgannmary
Sent: Monday, May 6, 2019 12:53 PM
To: [hidden email]
Subject: Trim Right And Left Blank Spaces

Hi,

I'm working with variables that are alphanumeric and look like this, for
example:
Diagnosis Code
     A123
938512
 48300007

I need to remove the leading and trailing white space and have tried everything I can find in previous discussions, but nothing is working.

Any help would be appreciated.

Thank you!
Mary




--
Sent from: http://spssx-discussion.1045642.n5.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
Reply | Threaded
Open this post in threaded view
|

Re: Trim Right And Left Blank Spaces

Rick Oliver
Note that internally string variable values are always right padded to the defined width of the string variable, so rtrim does not alter the internal values of string variables. The extra space on the right is not considered when evaluating string values:  "abc" and "abc   " are evaluated as the same value. Extra space on the left  does affect the value and can be removed with ltrim.

There are cases in which rtrim is useful, such as concatenating strings with the concat function in code page mode. When evaluating length or substrings use the functions with the "char" prefix.


On Mon, May 6, 2019 at 12:00 PM Maguin, Eugene <[hidden email]> wrote:
Look at the ltrim and rtrim character functions.

X = ltrim(rtrim(x))

Gene Maguin

-----Original Message-----
From: SPSSX(r) Discussion <[hidden email]> On Behalf Of mcgannmary
Sent: Monday, May 6, 2019 12:53 PM
To: [hidden email]
Subject: Trim Right And Left Blank Spaces

Hi,

I'm working with variables that are alphanumeric and look like this, for
example:
Diagnosis Code
     A123
938512
 48300007

I need to remove the leading and trailing white space and have tried everything I can find in previous discussions, but nothing is working.

Any help would be appreciated.

Thank you!
Mary




--
Sent from: http://spssx-discussion.1045642.n5.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
===================== 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: Trim Right And Left Blank Spaces

Mary E Mcgann
In reply to this post by Maguin, Eugene
Thank You, Gene.

I gave the code below a try and I'm getting the same message I received with other attempts.

>Error # 1.  Command name: Prcdr_CD_1
>The first word in the line is not recognized as an SPSS Statistics command.
>Execution of this command stops.
Prcdr_CD_1= ltrim(rtrim(Prcdr_CD_1)).

Prcdr_CD_1 currently lives in my data set and I've also tried computing it as a new variable to see if trimming would work in that context, but no luck. I like the simplicity of what you have shared. Why would the command not be recognized?

Ideas?

-----Original Message-----
From: SPSSX(r) Discussion <[hidden email]> On Behalf Of Maguin, Eugene
Sent: Monday, May 6, 2019 10:01 AM
To: [hidden email]
Subject: Re: Trim Right And Left Blank Spaces

Look at the ltrim and rtrim character functions.

X = ltrim(rtrim(x))

Gene Maguin

-----Original Message-----
From: SPSSX(r) Discussion <[hidden email]> On Behalf Of mcgannmary
Sent: Monday, May 6, 2019 12:53 PM
To: [hidden email]
Subject: Trim Right And Left Blank Spaces

Hi,

I'm working with variables that are alphanumeric and look like this, for
example:
Diagnosis Code
     A123
938512
 48300007

I need to remove the leading and trailing white space and have tried everything I can find in previous discussions, but nothing is working.

Any help would be appreciated.

Thank you!
Mary




--
Sent from: http://spssx-discussion.1045642.n5.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

=====================
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: Trim Right And Left Blank Spaces

Kevin longfield
Mary,

You just need to add the "Compute" to the beginning of that command

Compute Prcdr_CD_1= ltrim(rtrim(Prcdr_CD_1)).

Kevin.

On Mon, May 6, 2019 at 1:39 PM Mary E Mcgann <[hidden email]> wrote:
Thank You, Gene.

I gave the code below a try and I'm getting the same message I received with other attempts.

>Error # 1.  Command name: Prcdr_CD_1
>The first word in the line is not recognized as an SPSS Statistics command.
>Execution of this command stops.
Prcdr_CD_1= ltrim(rtrim(Prcdr_CD_1)).

Prcdr_CD_1 currently lives in my data set and I've also tried computing it as a new variable to see if trimming would work in that context, but no luck. I like the simplicity of what you have shared. Why would the command not be recognized?

Ideas?

-----Original Message-----
From: SPSSX(r) Discussion <[hidden email]> On Behalf Of Maguin, Eugene
Sent: Monday, May 6, 2019 10:01 AM
To: [hidden email]
Subject: Re: Trim Right And Left Blank Spaces

Look at the ltrim and rtrim character functions.

X = ltrim(rtrim(x))

Gene Maguin

-----Original Message-----
From: SPSSX(r) Discussion <[hidden email]> On Behalf Of mcgannmary
Sent: Monday, May 6, 2019 12:53 PM
To: [hidden email]
Subject: Trim Right And Left Blank Spaces

Hi,

I'm working with variables that are alphanumeric and look like this, for
example:
Diagnosis Code
     A123
938512
 48300007

I need to remove the leading and trailing white space and have tried everything I can find in previous discussions, but nothing is working.

Any help would be appreciated.

Thank you!
Mary




--
Sent from: http://spssx-discussion.1045642.n5.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

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


--
Kevin Longfield
(586) 419 - 5838
Vice President - Data Operations
www.phoenixmi.com
CONFIDENTIALITY NOTICE: This email message and any attachments are for the sole use of the intended recipient(s) and may contain proprietary, confidential, trade secret or privileged information. Any unauthorized review, use, disclosure or distribution is prohibited and may be a violation of law. If you are not the intended recipient or a person responsible for delivering this message to an intended recipient, please contact the sender by reply email and destroy all copies of the original message.  

--
This electronic message, including its attachments (if any), is CONFIDENTIAL and may contain PROPRIETARY or LEGALLY PRIVILEGED information. If you are not the intended recipient, you are hereby notified that any use, disclosure, copying, or distribution of this message, its attachments, or any of the information included therein, is unauthorized and strictly prohibited. If you have received this message in error, please immediately notify the sender by reply e-mail and permanently delete this message and its attachments, along with any copies thereof.

===================== 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: Trim Right And Left Blank Spaces

Mary E Mcgann

Thank you, Kevin. It is working great now 😊

Mary

 

 

From: Kevin Longfield <[hidden email]>
Sent: Monday, May 6, 2019 10:44 AM
To: Mary E Mcgann <[hidden email]>
Cc: [hidden email]
Subject: Re: Trim Right And Left Blank Spaces

 

Mary,

 

You just need to add the "Compute" to the beginning of that command

 

Compute Prcdr_CD_1= ltrim(rtrim(Prcdr_CD_1)).

 

Kevin.

 

On Mon, May 6, 2019 at 1:39 PM Mary E Mcgann <[hidden email]> wrote:

Thank You, Gene.

I gave the code below a try and I'm getting the same message I received with other attempts.

>Error # 1.  Command name: Prcdr_CD_1
>The first word in the line is not recognized as an SPSS Statistics command.
>Execution of this command stops.
Prcdr_CD_1= ltrim(rtrim(Prcdr_CD_1)).

Prcdr_CD_1 currently lives in my data set and I've also tried computing it as a new variable to see if trimming would work in that context, but no luck. I like the simplicity of what you have shared. Why would the command not be recognized?

Ideas?

-----Original Message-----
From: SPSSX(r) Discussion <[hidden email]> On Behalf Of Maguin, Eugene
Sent: Monday, May 6, 2019 10:01 AM
To: [hidden email]
Subject: Re: Trim Right And Left Blank Spaces

Look at the ltrim and rtrim character functions.

X = ltrim(rtrim(x))

Gene Maguin

-----Original Message-----
From: SPSSX(r) Discussion <[hidden email]> On Behalf Of mcgannmary
Sent: Monday, May 6, 2019 12:53 PM
To: [hidden email]
Subject: Trim Right And Left Blank Spaces

Hi,

I'm working with variables that are alphanumeric and look like this, for
example:
Diagnosis Code
     A123
938512
 48300007

I need to remove the leading and trailing white space and have tried everything I can find in previous discussions, but nothing is working.

Any help would be appreciated.

Thank you!
Mary




--
Sent from: http://spssx-discussion.1045642.n5.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

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


 

--

Kevin Longfield

(586) 419 - 5838
Vice President - Data Operations
www.phoenixmi.com

CONFIDENTIALITY NOTICE: This email message and any attachments are for the sole use of the intended recipient(s) and may contain proprietary, confidential, trade secret or privileged information. Any unauthorized review, use, disclosure or distribution is prohibited and may be a violation of law. If you are not the intended recipient or a person responsible for delivering this message to an intended recipient, please contact the sender by reply email and destroy all copies of the original message.  

 

--

This electronic message, including its attachments (if any), is CONFIDENTIAL and may contain PROPRIETARY or LEGALLY PRIVILEGED information. If you are not the intended recipient, you are hereby notified that any use, disclosure, copying, or distribution of this message, its attachments, or any of the information included therein, is unauthorized and strictly prohibited. If you have received this message in error, please immediately notify the sender by reply e-mail and permanently delete this message and its attachments, along with any copies thereof.

 

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