Remove spaces from postcode

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

Remove spaces from postcode

Kuiama Thompson

Hiya

 

I have a postcode variable which contains postcodes in a number of different formats.  I want to make a copy of all the postcodes and remove the spaces from each postcode in the new variable.

I can do this using the windows interface but I can’t work out the syntax.  Can anyone help?

 

Thanks

Kuiama

 

DISCLAIMER:
This email has been scanned for viruses, however we are unable to accept responsibility for any damage caused by the contents. The opinions expressed in this email represent the views of the sender, not Salford PCT unless explicitly stated. If you have received this email in error please notify the sender. The information contained in this email may be subject to public disclosure under the NHS Code of Openness or the Freedom of Information Act 2000. Unless the information is legally exempt from disclosure, the confidentiality of this e-mail and your reply cannot be guaranteed.

Reply | Threaded
Open this post in threaded view
|

Re: Remove spaces from postcode

Albert-Jan Roskam
Hi!
 
I assumed you also wanted everything in CAPS:
 
data list free / postcode (a8).
begin data
"21 23 ab"
"123 44"
" 21 23 AA"
end data.
compute postcode = upcase(replace(postcode, " ", "")).


Cheers!!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--- On Wed, 4/28/10, Kuiama Thompson <[hidden email]> wrote:

From: Kuiama Thompson <[hidden email]>
Subject: [SPSSX-L] Remove spaces from postcode
To: [hidden email]
Date: Wednesday, April 28, 2010, 4:09 PM

Hiya

 

I have a postcode variable which contains postcodes in a number of different formats.  I want to make a copy of all the postcodes and remove the spaces from each postcode in the new variable.

I can do this using the windows interface but I can’t work out the syntax.  Can anyone help?

 

Thanks

Kuiama

 

DISCLAIMER:
This email has been scanned for viruses, however we are unable to accept responsibility for any damage caused by the contents. The opinions expressed in this email represent the views of the sender, not Salford PCT unless explicitly stated. If you have received this email in error please notify the sender. The information contained in this email may be subject to public disclosure under the NHS Code of Openness or the Freedom of Information Act 2000. Unless the information is legally exempt from disclosure, the confidentiality of this e-mail and your reply cannot be guaranteed.

Reply | Threaded
Open this post in threaded view
|

Re: Remove spaces from postcode

Maguin, Eugene
In reply to this post by Kuiama Thompson
Kuiama,

This may not be the more elegant method and it does not exploit any
structural elements in the UK postal code but:
Let Incode(a10) be the existing postal code values and Outcode(a10) be the
ones stripped of blanks.

Compute #j=0.
Loop #i=1 to 10.
Do if (substr(incode,#i,1) ne ' ').
+  compute #j=#j+1.
+  compute substr(outcode,#j,1)=substr(incode,#i,1).
End if.
End loop.

Gene Maguin


>>I have a postcode variable which contains postcodes in a number of
different formats.  I want to make a copy of all the postcodes and remove
the spaces from each postcode in the new variable.

I can do this using the windows interface but I can't work out the syntax.
Can anyone help?

Thanks
Kuiama

=====================
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: Remove spaces from postcode

Bruce Weaver
Administrator
In reply to this post by Kuiama Thompson
Kuiama Thompson wrote
Hiya

I have a postcode variable which contains postcodes in a number of
different formats.  I want to make a copy of all the postcodes and
remove the spaces from each postcode in the new variable.

I can do this using the windows interface but I can't work out the
syntax.  Can anyone help?

Thanks

Kuiama

Use the REPLACE function to replace " " with "".


REPLACE. REPLACE(a1, a2, a3[, a4]). String. In a1, instances of a2 are replaced with a3. The optional argument a4 specifies the number of occurrences to replace; if a4 is omitted, all occurrences are replaced. Arguments a1, a2, and a3 must resolve to string values (literal strings enclosed in quotes or string variables), and the optional argument a4 must resolve to a non-negative integer. For example, REPLACE("abcabc", "a", "x") returns a value of "xbcxbc" and REPLACE("abcabc", "a", "x", 1) returns a value of "xbcabc".

--
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: Remove spaces from postcode

Maguin, Eugene
In reply to this post by Albert-Jan Roskam
Albert-Jan and Bruce,

Thanks for your posting. It never would have occurred to me that 'no
character' could be specified to replace a character. I would have expected
an error to result. I don't think that there are any other string functions
were a 'no character' would make sense but if there is/are other functions
will a 'no character' specification work there also?

Gene Maguin

=====================
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: Remove spaces from postcode

Art Kendall
In reply to this post by Kuiama Thompson
You received a few answers that should address your question.  This addresses a different aspect of the situation.

The GUI (Graphic User Interface with menus etc) is an excellent tool for generating a first draft of syntax.  Once you have the GUI doing (close to) what you want exit via <paste>. That saves the syntax so that you will remember what you were doing before you were distracted by  a phone call or whatever.  The syntax is also critical in producing an "audit trail".  It also allows you to back and refine your process so that it is more readable and adaptable.  If you have problems with syntax, showing the syntax you are attempting makes it more likely that others will be able to help you.

Art Kendall
Social Research Consultants


On 4/28/2010 10:09 AM, Kuiama Thompson wrote:

Hiya

 

I have a postcode variable which contains postcodes in a number of different formats.  I want to make a copy of all the postcodes and remove the spaces from each postcode in the new variable.

I can do this using the windows interface but I can’t work out the syntax.  Can anyone help?

 

Thanks

Kuiama

 

DISCLAIMER:
This email has been scanned for viruses, however we are unable to accept responsibility for any damage caused by the contents. The opinions expressed in this email represent the views of the sender, not Salford PCT unless explicitly stated. If you have received this email in error please notify the sender. The information contained in this email may be subject to public disclosure under the NHS Code of Openness or the Freedom of Information Act 2000. Unless the information is legally exempt from disclosure, the confidentiality of this e-mail and your reply cannot be guaranteed.

===================== 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: Remove spaces from postcode

Art Kendall
In reply to this post by Kuiama Thompson
You received a few answers that should address your question.  This addresses a different aspect of the situation.

The GUI (Graphic User Interface with menus etc) is an excellent tool for generating a first draft of syntax.  Once you have the GUI doing (close to) what you want exit via <paste>. That saves the syntax so that you will remember what you were doing before you were distracted by  a phone call or whatever.  The syntax is also critical in producing an "audit trail".  It also allows you to back and refine your process so that it is more readable and adaptable.  If you have problems with syntax, showing the syntax you are attempting makes it more likely that others will be able to help you.

Art Kendall
Social Research Consultants


On 4/28/2010 10:09 AM, Kuiama Thompson wrote:

Hiya

 

I have a postcode variable which contains postcodes in a number of different formats.  I want to make a copy of all the postcodes and remove the spaces from each postcode in the new variable.

I can do this using the windows interface but I can’t work out the syntax.  Can anyone help?

 

Thanks

Kuiama

 

DISCLAIMER:
This email has been scanned for viruses, however we are unable to accept responsibility for any damage caused by the contents. The opinions expressed in this email represent the views of the sender, not Salford PCT unless explicitly stated. If you have received this email in error please notify the sender. The information contained in this email may be subject to public disclosure under the NHS Code of Openness or the Freedom of Information Act 2000. Unless the information is legally exempt from disclosure, the confidentiality of this e-mail and your reply cannot be guaranteed.

===================== 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: Remove spaces from postcode

Art Kendall
In reply to this post by Kuiama Thompson
I thought you were using the menus which have string functions such as REPLACE available under <transform>.  Were you using <edit><replace> under the data view?

Art

On 4/29/2010 4:30 AM, Kuiama Thompson wrote:
The way I did this via the GUI was to do a find and replace (find the space and replace with nothing) but this function doesn't allow me to paste into the syntax.  At the moment I keep having to run half of my syntax, do the find and replace and then run the rest of the syntax.
 
Unfortunately I'm not in the office today so I can't try the suggestions I've received but I'll have a go tomorrow.
 
Thanks for your help,
Kuiama
 
 
-----Original Message-----
From: Art Kendall [[hidden email]]
Sent: 28 April 2010 17:30
To: Kuiama Thompson
Cc: [hidden email]
Subject: Re: [SPSSX-L] Remove spaces from postcode

You received a few answers that should address your question.  This addresses a different aspect of the situation.

The GUI (Graphic User Interface with menus etc) is an excellent tool for generating a first draft of syntax.  Once you have the GUI doing (close to) what you want exit via <paste>. That saves the syntax so that you will remember what you were doing before you were distracted by  a phone call or whatever.  The syntax is also critical in producing an "audit trail".  It also allows you to back and refine your process so that it is more readable and adaptable.  If you have problems with syntax, showing the syntax you are attempting makes it more likely that others will be able to help you.

Art Kendall
Social Research Consultants


On 4/28/2010 10:09 AM, Kuiama Thompson wrote:

Hiya

I have a postcode variable which contains postcodes in a number of different formats.  I want to make a copy of all the postcodes and remove the spaces from each postcode in the new variable.

I can do this using the windows interface but I can’t work out the syntax.  Can anyone help?

Thanks

Kuiama

DISCLAIMER:
This email has been scanned for viruses, however we are unable to accept responsibility for any damage caused by the contents. The opinions expressed in this email represent the views of the sender, not Salford PCT unless explicitly stated. If you have received this email in error please notify the sender. The information contained in this email may be subject to public disclosure under the NHS Code of Openness or the Freedom of Information Act 2000. Unless the information is legally exempt from disclosure, the confidentiality of this e-mail and your reply cannot be guaranteed.

DISCLAIMER:
This email has been scanned for viruses, however we are unable to accept responsibility for any damage caused by the contents. The opinions expressed in this email represent the views of the sender, not Salford PCT unless explicitly stated. If you have received this email in error please notify the sender. The information contained in this email may be subject to public disclosure under the NHS Code of Openness or the Freedom of Information Act 2000. Unless the information is legally exempt from disclosure, the confidentiality of this e-mail and your reply cannot be guaranteed.

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