separating two varibales

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

separating two varibales

abdelrhman elmubarak
 

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

 


check out the rest of the Windows Live™. More than mail–Windows Live™ goes way beyond your inbox. More than messages
Reply | Threaded
Open this post in threaded view
|

Re: separating two varibales

Bruce Weaver
Administrator
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@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
|

python syntax error pointing to empty space

mpirritano
In reply to this post by abdelrhman elmubarak

Python question,

 

Why do I sometimes get a syntax error in python that points to empty space. It looks like this. I’ve gotten this before and remedied it by deleting blank space at the end of the program. This time it’s not working. The blank space comes after a python if statement that precedes an spss.submit block.

 

Here’s the error:

 

  File "C:\Projects\ute_pos.py", line 120

 

                                         ^

 

Thanks

matt

 

 

Matthew Pirritano, Ph.D.

Research Analyst IV

Medical Services Initiative (MSI)

Orange County Health Care Agency

(714) 568-5648

Reply | Threaded
Open this post in threaded view
|

Re: separating two varibales

Roberts, Michael
In reply to this post by Bruce Weaver
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:[hidden email]] On Behalf Of
Bruce Weaver
Sent: Monday, July 06, 2009 10:03 AM
To: [hidden email]
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
[hidden email]
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.html
Sent from the SPSSX Discussion mailing list archive at 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