SYNTAX TO ADD INTERNATIONAL DIALLING CODE

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

SYNTAX TO ADD INTERNATIONAL DIALLING CODE

researcher
Dear SPSS people I would be extremely grateful if someone can suggest syntax to do following I have about 1,000 UK mobile numbers which are mostly 11 digits , without UK dialling code (+44) e.g. they look like this 07970471126 But I need to create a new variable which includes UK international dialling code i.e. to add +44 and drop the first zero in the number so that the above would become +447970471126 This is needed to prepare a distribution list for an SMS survey in Qualtrics A small proportion of the numbers have 10 rather than 11 digits but they are valid numbers Fairly urgent project =- all thoughts very welcome Thanks
Reply | Threaded
Open this post in threaded view
|

Re: SYNTAX TO ADD INTERNATIONAL DIALLING CODE

Bruce Weaver
Administrator
Look up the CONCAT function.  E.g.,

* Read in some data to illustrate.
NEW FILE.
DATASET CLOSE ALL.
DATA LIST LIST / phone1 (A11).
BEGIN DATA
"07970471126"
"0123456789"
END DATA.
* Declare new string variable for code+number.
STRING phone2 (A14).
* Use CONCAT function to join +44 and phone1.
COMPUTE phone2 = CONCAT("+44", phone1).
LIST.

Output from the LIST command:  

phone1      phone2
 
07970471126 +4407970471126
0123456789  +440123456789


--
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: SYNTAX TO ADD INTERNATIONAL DIALLING CODE

researcher
Thanks a lot Bruce

I would still need to lose the first zero somehow  but  that look useful

Excuse my ignorance but what is 'begin data' and 'end data' actually doing?   Is that specifying a range of cases in the variable so that if I wanted to do all the case I would not need to use that?

Appreciate your help

Mike
Reply | Threaded
Open this post in threaded view
|

Re: SYNTAX TO ADD INTERNATIONAL DIALLING CODE

Bruce Weaver
Administrator
Use LTRIM to remove the leading 0:

COMPUTE phone2 = CONCAT("+44", LTRIM(phone1,"0")).

The BEGIN DATA and END DATA lines in my code are just part of the DATA LIST command I used to read in some data to illustrate the approach.  You can ignore those lines, as you already have a data file.  All you need is this bit:

STRING phone2 (A14).
COMPUTE phone2 = CONCAT("+44", LTRIM(phone1,"0")).
EXECUTE.

Replace phone1 and phone2 with your own variable names.  


researcher wrote
Thanks a lot Bruce

I would still need to lose the first zero somehow  but  that look useful

Excuse my ignorance but what is 'begin data' and 'end data' actually doing?   Is that specifying a range of cases in the variable so that if I wanted to do all the case I would not need to use that?

Appreciate your help

Mike
--
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/).