I am interested in mapping patient origin from zip code. Our zip codes are currently 9 character strings, but our mapping software can only read five character zip codes. Does anyone on the list know of a method in SPSS that will allow me to create a 5 character zip code variable by lopping off the last four characters (e.g., 06451333 would become 06451).
Thanks Allen |
HI Allen,
You can try this, data list list / ZIP(a9). begin data. 064513330 075101210 123456789 end data. STRING ZIP_five(A5). COMPUTE ZIP_five=RTRIM(SUBSTR(ZIP,INDEX(ZIP,',')+1)). EXECUTE. Cheers! Mahbub -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Frommelt, Allen Sent: 7-Jul-06 2:28 PM To: [hidden email] Subject: Truncating zip code I am interested in mapping patient origin from zip code. Our zip codes are currently 9 character strings, but our mapping software can only read five character zip codes. Does anyone on the list know of a method in SPSS that will allow me to create a 5 character zip code variable by lopping off the last four characters (e.g., 06451333 would become 06451). Thanks Allen |
In reply to this post by Frommelt, Allen
If zip code is a number, use the trunc function, as in:
compute newzip=trunc(oldzip/10000). If it's a string, create a new string variable that's only 5-characters and then set it equal to the old string, which will get truncated, as in: string newzip (a5) compute newzip=oldzip. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Frommelt, Allen Sent: Friday, July 07, 2006 1:28 PM To: [hidden email] Subject: Truncating zip code I am interested in mapping patient origin from zip code. Our zip codes are currently 9 character strings, but our mapping software can only read five character zip codes. Does anyone on the list know of a method in SPSS that will allow me to create a 5 character zip code variable by lopping off the last four characters (e.g., 06451333 would become 06451). Thanks Allen |
In reply to this post by Frommelt, Allen
Try this:
STRING zip (A5) . COMPUTE zip = SUBSTR(ZIPCODE,1,5) . EXECUTE . "Frommelt, Allen" <[hidden email]> Sent by: "SPSSX(r) Discussion" <[hidden email]> 07/07/2006 02:28 PM Please respond to "Frommelt, Allen" <[hidden email]> To [hidden email] cc Subject Truncating zip code I am interested in mapping patient origin from zip code. Our zip codes are currently 9 character strings, but our mapping software can only read five character zip codes. Does anyone on the list know of a method in SPSS that will allow me to create a 5 character zip code variable by lopping off the last four characters (e.g., 06451333 would become 06451). Thanks Allen |
In reply to this post by Frommelt, Allen
This solution is a tad more complex than it needs to be. Specifically, the COMPUTE statement can be simplified to:
compute zip_five=zip. This will result in a truncated string if zip_five is defined as A5 (as in your example). -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Mahbub Khandoker Sent: Friday, July 07, 2006 1:43 PM To: [hidden email] Subject: Re: Truncating zip code HI Allen, You can try this, data list list / ZIP(a9). begin data. 064513330 075101210 123456789 end data. STRING ZIP_five(A5). COMPUTE ZIP_five=RTRIM(SUBSTR(ZIP,INDEX(ZIP,',')+1)). EXECUTE. Cheers! Mahbub -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Frommelt, Allen Sent: 7-Jul-06 2:28 PM To: [hidden email] Subject: Truncating zip code I am interested in mapping patient origin from zip code. Our zip codes are currently 9 character strings, but our mapping software can only read five character zip codes. Does anyone on the list know of a method in SPSS that will allow me to create a 5 character zip code variable by lopping off the last four characters (e.g., 06451333 would become 06451). Thanks Allen |
In reply to this post by Frommelt, Allen
Use This one.
STRING ZIP_NEW (A5). COMPUTE ZIP_NEW = SUBSTR(ZIP,1,5) . EXECUTE . -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Frommelt, Allen Sent: Friday, July 07, 2006 2:28 PM To: [hidden email] Subject: Truncating zip code I am interested in mapping patient origin from zip code. Our zip codes are currently 9 character strings, but our mapping software can only read five character zip codes. Does anyone on the list know of a method in SPSS that will allow me to create a 5 character zip code variable by lopping off the last four characters (e.g., 06451333 would become 06451). Thanks Allen |
In reply to this post by Frommelt, Allen
I wanted to thank everyone for your help. I have successfully truncated my zip code so we can now map the data.
Thanks Allen |
Free forum by Nabble | Edit this page |