This works for the trailing characters:
compute phone = rtrim(rtrim(phone),')').
Although I think your new code has a lot more interesting possibilities
(for me at least)!
HTH
Mike
-----Original Message-----
From: SPSSX(r) Discussion [mailto:
SPSSX-L@...] On Behalf Of
Bruce Weaver
Sent: Monday, July 06, 2009 10:03 AM
To:
SPSSX-L@...
Subject: Re: separating two varibales
abdelrhman elmubarak wrote:
>
>
>
>
> Hi
> My data looks as below
>
>
> customer name
>
> MOHAMMAD HAIDER TUBEGU(0951191311)
> SAED ALWE MATOMATODY
> HASSAN MOHD,HASSAN ALSAFFI(0901508033)
>
> I want to separate contact number from customer name as below
>
>
> customer name contact number
>
> MOHAMMAD HAIDER TUBEGU 0951191311
> SAED ALWE MATOMATODY
> HASSAN MOHD,HASSAN ALSAFFI 0901508033
>
> Thanks in advance
>
> Abdulrahman
>
>
Assuming the contact number is always enclosed in parentheses, and comes
after the name, this should do the trick.
data list list / custname(a50).
begin data
"MOHAMMAD HAIDER TUBEGU(0951191311)"
"SAED ALWE MATOMATODY"
"HASSAN MOHD,HASSAN ALSAFFI(0901508033)"
end data.
string phone(a25).
compute #pos = index(custname,"(").
do if #pos GT 0.
- compute phone = substr(custname,#pos+1).
- compute phone = replace(phone,")","").
- compute custname = substr(custname,1,#pos-1).
end if.
exe.
I first tried
- compute phone = RTRIM(phone,")").
to get rid of the ")" on the end of the contact number, but it was not
working for some reason, so I switched to REPLACE. Does anyone have any
thoughts about what was going wrong there? When I say it wasn't
working, it
did not cause an error, it just failed to remove the ")" from the end of
the
string. The same thing happened when I tried
- compute phone = RTRIM(phone," ").
- compute phone = RTRIM(phone,")").
in case there were trailing blanks that were messing things up.
-----
--
Bruce Weaver
bweaver@...
http://sites.google.com/a/lakeheadu.ca/bweaver/"When all else fails, RTFM."
--
View this message in context:
http://www.nabble.com/separating-two-varibales-tp24354662p24355998.htmlSent from the SPSSX Discussion mailing list archive at Nabble.com.
=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@... (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
LISTSERV@... (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