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.