Removing first 3 letters from a string in SPSS

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

Removing first 3 letters from a string in SPSS

sijuisijali
I have a file with a string coded XXX123. I am trying to use LTRIM to
remove XXX, but it keeps coming back with errors. Any help on how to
use the LTRIM function to do this?

Thanks!

=====================
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: Removing first 3 letters from a string in SPSS

GauravSrivastava
• To control the width of strings, use the functions that are available for padding (LPADRPAD), trimming (LTRIMRTRIM), and selecting a portion of strings (SUBSTR).

Try to use INDEX, SUBSTR and REPLACE.

Regards,
Gaurav


On Thu, Dec 13, 2012 at 4:41 PM, Lyle McKinnon <[hidden email]> wrote:
I have a file with a string coded XXX123. I am trying to use LTRIM to
remove XXX, but it keeps coming back with errors. Any help on how to
use the LTRIM function to do this?

Thanks!

=====================
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: Removing first 3 letters from a string in SPSS

Bruce Weaver
Administrator
In reply to this post by sijuisijali
Please post the syntax you are using with a small dataset that illustrates the problem.


sijuisijali wrote
I have a file with a string coded XXX123. I am trying to use LTRIM to
remove XXX, but it keeps coming back with errors. Any help on how to
use the LTRIM function to do this?

Thanks!

=====================
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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Removing first 3 letters from a string in SPSS

Art Kendall
In reply to this post by sijuisijali
see if this does what you want.

data list list /oldstring  (a6).
begin data
abc234
ABC789
XXX123
xxx12
xxx1
end data.
string newstring (a3).
compute newstring = substr(oldstring, 4, 3).
compute newnumber = number(newstring,f3).
list.

Art Kendall
Social Research Consultants
On 12/13/2012 6:11 AM, Lyle McKinnon wrote:
I have a file with a string coded XXX123. I am trying to use LTRIM to
remove XXX, but it keeps coming back with errors. Any help on how to
use the LTRIM function to do this?

Thanks!

=====================
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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Removing first 3 letters from a string in SPSS

sijuisijali
Thanks that worked great!

Lyle

On 13 December 2012 15:45, Art Kendall <[hidden email]> wrote:

> see if this does what you want.
>
> data list list /oldstring  (a6).
> begin data
> abc234
> ABC789
> XXX123
> xxx12
> xxx1
> end data.
> string newstring (a3).
> compute newstring = substr(oldstring, 4, 3).
> compute newnumber = number(newstring,f3).
> list.
>
> Art Kendall
> Social Research Consultants
>
> On 12/13/2012 6:11 AM, Lyle McKinnon wrote:
>
> I have a file with a string coded XXX123. I am trying to use LTRIM to
> remove XXX, but it keeps coming back with errors. Any help on how to
> use the LTRIM function to do this?
>
> Thanks!
>
> =====================
> 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: Removing first 3 letters from a string in SPSS

Art Kendall
You're welcome.
Art Kendall
Social Research Consultants
On 12/13/2012 7:57 AM, Lyle McKinnon wrote:
Thanks that worked great!

Lyle

On 13 December 2012 15:45, Art Kendall [hidden email] wrote:
see if this does what you want.

data list list /oldstring  (a6).
begin data
abc234
ABC789
XXX123
xxx12
xxx1
end data.
string newstring (a3).
compute newstring = substr(oldstring, 4, 3).
compute newnumber = number(newstring,f3).
list.

Art Kendall
Social Research Consultants

On 12/13/2012 6:11 AM, Lyle McKinnon wrote:

I have a file with a string coded XXX123. I am trying to use LTRIM to
remove XXX, but it keeps coming back with errors. Any help on how to
use the LTRIM function to do this?

Thanks!

=====================
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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Removing first 3 letters from a string in SPSS

David Marso
Administrator
In reply to this post by Art Kendall
NOTES and slight expandorama:
--
If you are after stripping the first 3 to retain everything beyond you can omit the 3rd argument .
You do need to declare the appropriate length in the *PRECEDING* STRING declarative..
COMPUTE newstring = CHAR.SUBSTR(oldstring, 4).

IF you do want to simply convert the rest to a number you can even omit that housekeeping:

COMPUTE numvar = NUMBER(CHAR.SUBSTR(oldstring, 4),F8).

To keep any leading zeros:
COMPUTE numvar = NUMBER(CHAR.SUBSTR(oldstring, 4),N8).




Art Kendall wrote
see if this does what
        you want.
       
        data list list /oldstring  (a6).
          begin data
          abc234
          ABC789
          XXX123
          xxx12
          xxx1
          end data.
          string newstring (a3).
          compute newstring = substr(oldstring, 4, 3).
          compute newnumber = number(newstring,f3).
          list.
     
      Art Kendall
Social Research Consultants
      On 12/13/2012 6:11 AM, Lyle McKinnon wrote:
   
   
      I have a file with a string coded XXX123. I am trying to use LTRIM to
remove XXX, but it keeps coming back with errors. Any help on how to
use the LTRIM function to do this?

Thanks!

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