|
Hi Listserv-
I have a table that has data that I am pulling in from excel. In comes into SPSS with the type as numeric with a length of 11. This variable (ProvID) should all be 8 long and I need to change it to a string variable. However, here are my issues. First, all of these variables should be 8, but some of them are 7 because excel removed the leading zero. So, I need to add a leading zero to some of them, and wondering if someone had syntax for this. Also, when it goes into string from numeric, a get some spaces in the beginning of the number, which I need removed. Any help with this would be much appreciated! Thanks, Jenny ===================== 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 |
|
What syntax are you using now?
If the variable is really numeric, then it doesn't have a length of 11--11 digits is a format used to display a floating point number. The string function on a COMPUTE command changes a number to a string value. The STRING requires two arguments: 1) the value to be changed, usually a variable, and 2) a format to use when converting it. The N format will place a zero at the beginning of what is otherwise a 7 digit number, so something like the following should work: STRING newstring(a8). COMPUTE newstring=COMPUTE(var00001,n8). If var00001 is larger than 8 digits, the results will be set to ******** which is how an overflow value is represented within SPSS. Look at the example in Help>Command Syntax Reference>Universals>Transformation Expressions>String/Numeric Conversion Functions. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jennifer Steffes Sent: Wednesday, November 28, 2007 8:18 AM To: [hidden email] Subject: Adding a leading zero and removing spaces Hi Listserv- I have a table that has data that I am pulling in from excel. In comes into SPSS with the type as numeric with a length of 11. This variable (ProvID) should all be 8 long and I need to change it to a string variable. However, here are my issues. First, all of these variables should be 8, but some of them are 7 because excel removed the leading zero. So, I need to add a leading zero to some of them, and wondering if someone had syntax for this. Also, when it goes into string from numeric, a get some spaces in the beginning of the number, which I need removed. Any help with this would be much appreciated! Thanks, Jenny ===================== 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 |
|
In reply to this post by Jennifer Steffes
JENNY, THIS IS WHAT I DO WHEN I HAVE THAT PROBLEM:
* Create the field E with 9 decimals COMPUTE E = provid / 10000000000 . EXECUTE . * SET E TO STRING STRING W(A8). COMPUTE w = SUBSTR(E,4,8) . EXECUTE . Barbara -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jennifer Steffes Sent: Wednesday, November 28, 2007 10:18 AM To: [hidden email] Subject: Adding a leading zero and removing spaces Hi Listserv- I have a table that has data that I am pulling in from excel. In comes into SPSS with the type as numeric with a length of 11. This variable (ProvID) should all be 8 long and I need to change it to a string variable. However, here are my issues. First, all of these variables should be 8, but some of them are 7 because excel removed the leading zero. So, I need to add a leading zero to some of them, and wondering if someone had syntax for this. Also, when it goes into string from numeric, a get some spaces in the beginning of the number, which I need removed. Any help with this would be much appreciated! Thanks, Jenny ===================== 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 |
|
*create some sample data.
data list free /numvar (f11). begin data 1 12 123 1234 12345 1234567 12345678 end data. *now the real code. string stringvar (a8). compute stringvar=string(numvar, n8). *alternatively, just change the format of numvar. formats numvar (n8). execute. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Lombardo, Barbara Sent: Thursday, November 29, 2007 10:01 AM To: [hidden email] Subject: Re: Adding a leading zero and removing spaces JENNY, THIS IS WHAT I DO WHEN I HAVE THAT PROBLEM: * Create the field E with 9 decimals COMPUTE E = provid / 10000000000 . EXECUTE . * SET E TO STRING STRING W(A8). COMPUTE w = SUBSTR(E,4,8) . EXECUTE . Barbara -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Jennifer Steffes Sent: Wednesday, November 28, 2007 10:18 AM To: [hidden email] Subject: Adding a leading zero and removing spaces Hi Listserv- I have a table that has data that I am pulling in from excel. In comes into SPSS with the type as numeric with a length of 11. This variable (ProvID) should all be 8 long and I need to change it to a string variable. However, here are my issues. First, all of these variables should be 8, but some of them are 7 because excel removed the leading zero. So, I need to add a leading zero to some of them, and wondering if someone had syntax for this. Also, when it goes into string from numeric, a get some spaces in the beginning of the number, which I need removed. Any help with this would be much appreciated! Thanks, Jenny ===================== 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 ===================== 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 |
| Free forum by Nabble | Edit this page |
