|
Hello,
I have a dataset in which I have predefined variables. They all imported as string variables. How do I change them to numeric without changing the name? Thanks ===================== 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 |
|
>>I have a dataset in which I have predefined variables. They all imported
as string variables. How do I change them to numeric without changing the name? I suspect that you can manually edit the variable definition in the variable view of the data window. I have never tried this, so I don't know if it will work. In syntax, it's almost no easier. Let your current variables be A1 to A50. Rename variables (A1 to A50=X1 to X50). Do repeat X=X1 to X50/A=A1 to A50. + compute A=number(X,f8.2). End repeat. Execute. Delete variables X1 to X50. 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 |
|
This syntax is followed by a RENAME VARIABLES command to rename the new
variables to the deleted old variables. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Gene Maguin Sent: Friday, October 19, 2007 1:25 PM To: [hidden email] Subject: Re: String to Numeric >>I have a dataset in which I have predefined variables. They all imported as string variables. How do I change them to numeric without changing the name? I suspect that you can manually edit the variable definition in the variable view of the data window. I have never tried this, so I don't know if it will work. In syntax, it's almost no easier. Let your current variables be A1 to A50. Rename variables (A1 to A50=X1 to X50). Do repeat X=X1 to X50/A=A1 to A50. + compute A=number(X,f8.2). End repeat. Execute. Delete variables X1 to X50. 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 ===================== 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 |
|
Dear Friends
First you create a file that load the names of the variables that you want convert (STRING TO NUMERIC). Example: DEFINE NomesVariaveisNumericas () var_1 var_2 var_3 . . . var_n !ENDDEFINE. Save and run this macro. Now write this new macro. Your problem end here: SET MPRINT OFF. SET WORKSPACE=500000. DEFINE StringforNumericV2 (variaveis=!CMDEND) NUMERIC TEMP(F20.4). COMPUTE TEMP=NUMBER(BASE, F20.0). MATCH FILES FILE=* /DROP=BASE. RENAME VARIABLE (TEMP=BASE). !DO !VarOriginal !IN (!variaveis) NUMERIC Temporaria(F20.4). COMPUTE Temporaria=NUMBER(!VarOriginal,F20.0). MATCH FILES FILE=* /DROP=!VarOriginal. RENAME VARIABLE (Temporaria=!VarOriginal). !DOEND. !ENDDEFINE. /*StringforNumericV2 /*variaveis = NomesVariaveisNumericas. Thanks for all and good work. Carlos Renato Statistician - UFPE - Risctec - Riscos Tecnológicos (+55)81.3581.1246 / (+55)81.2126.8728 R33/(+55)81.9926.5015 [hidden email] ====================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 Nyougo Omae.
Others have posted a solution to this problem, but in SPSS 16 there is a new command
ALTER TYPE that can change between numeric and string. It can also change the width of a string variable. And it can optimize the space for a string by resizing a string variable down to the minimum required to hold the data (or that value plus a little slack.) This command was motivated both by user requests for a way to change the type and to address size issues for those taking advantage of the new Unicode mode available in SPSS 16. Regards, Jon Peck -----Original Message----- From: SPSSX(r) Discussion on behalf of Nyougo Omae. Sent: Fri 10/19/2007 11:29 AM To: [hidden email] Subject: [SPSSX-L] String to Numeric Hello, I have a dataset in which I have predefined variables. They all imported as string variables. How do I change them to numeric without changing the name? Thanks ===================== 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 |
|
That is a VERY HANDY command! Thanks! Now let's hope
my company will upgrade to v16! Albert-Jan --- "Peck, Jon" <[hidden email]> wrote: > Others have posted a solution to this problem, but > in SPSS 16 there is a new command > > ALTER TYPE > > that can change between numeric and string. It can > also change the width of a string variable. And it > can optimize the space for a string by resizing a > string variable down to the minimum required to hold > the data (or that value plus a little slack.) > > This command was motivated both by user requests for > a way to change the type and to address size issues > for those taking advantage of the new Unicode mode > available in SPSS 16. > > Regards, > Jon Peck > > > -----Original Message----- > From: SPSSX(r) Discussion on behalf of Nyougo Omae. > Sent: Fri 10/19/2007 11:29 AM > To: [hidden email] > Subject: [SPSSX-L] String to Numeric > > Hello, > > I have a dataset in which I have predefined > variables. They all imported as string variables. > How do I change them to numeric without changing the > name? > > Thanks > > ===================== > 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 > Cheers! Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Did you know that 87.166253% of all statistics claim a precision of results that is not justified by the method employed? [HELMUT RICHTER] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.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 |
|
In reply to this post by Nyougo Omae.
I am looking forward to the ALTER TYPE command.
In the meantime, you would have to create a new variable: RENAME VARIABLES (MyVar = aMyVar) . RECODE aMyVar ('A'=1) ('B'=2) [ etc. ] INTO MyVar . MyVar is now a numeric variable. There are many variations on this. > -----Original Message----- > From: SPSSX(r) Discussion on behalf of Nyougo Omae. > Sent: Fri 10/19/2007 11:29 AM > To: [hidden email] > Subject: [SPSSX-L] String to Numeric > > Hello, > > I have a dataset in which I have predefined variables. They all > imported as string variables. > How do I change them to numeric without changing the name? > > Thanks > > ===================== > 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 |
|
Hi All,
I have string data that look like this: 4943795 30345740 230533689 119114564 I applied this code: numeric Tot_XN (F9.2). RECODE TotX (CONVERT) INTO Tot_XN. execute. ..and got this: 4943795.00 30345740.00 230533689.0 119114564.0 11914981.00 ...It needs to look like this: 49,437.95 303,457.40 2,305,336.89 1,191,145.64 119,149.81 I'm doing something wrong here....any ideas? Thanks a bunch. Carol ===================== 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 |
|
Carol:
You can add the '00' portion to the string version of your numbers: DATA LIST FREE /totX (a9). BEGIN DATA 4943795 30345740 230533689 119114564 END DATA. STRING numtxt(a9). COMPUTE numtxt = concat(rtrim(totX),'00'). NUMERIC tot_XN (F9.2). RECODE numtxt (CONVERT) INTO tot_XN. EXECUTE. This will work so long as your text versions always have at least 7 digits. --jim -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Parise, Carol A. Sent: Thursday, January 29, 2009 7:05 PM To: [hidden email] Subject: String to Numeric Hi All, I have string data that look like this: 4943795 30345740 230533689 119114564 I applied this code: numeric Tot_XN (F9.2). RECODE TotX (CONVERT) INTO Tot_XN. execute. ..and got this: 4943795.00 30345740.00 230533689.0 119114564.0 11914981.00 ...It needs to look like this: 49,437.95 303,457.40 2,305,336.89 1,191,145.64 119,149.81 I'm doing something wrong here....any ideas? Thanks a bunch. Carol ===================== 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 |
|
There are three issues here:
1. converting a string into a number. The number function does that. 2. dividing the number by 100 to get two decimal positions. 3. using the COMMA display format to the comma format. COMPUTE numvar=number(totx, f10). FORMAT numvar(comma15.2). -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Marks, Jim Sent: Thursday, January 29, 2009 6:54 PM To: [hidden email] Subject: Re: String to Numeric Carol: You can add the '00' portion to the string version of your numbers: DATA LIST FREE /totX (a9). BEGIN DATA 4943795 30345740 230533689 119114564 END DATA. STRING numtxt(a9). COMPUTE numtxt = concat(rtrim(totX),'00'). NUMERIC tot_XN (F9.2). RECODE numtxt (CONVERT) INTO tot_XN. EXECUTE. This will work so long as your text versions always have at least 7 digits. --jim -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Parise, Carol A. Sent: Thursday, January 29, 2009 7:05 PM To: [hidden email] Subject: String to Numeric Hi All, I have string data that look like this: 4943795 30345740 230533689 119114564 I applied this code: numeric Tot_XN (F9.2). RECODE TotX (CONVERT) INTO Tot_XN. execute. ..and got this: 4943795.00 30345740.00 230533689.0 119114564.0 11914981.00 ...It needs to look like this: 49,437.95 303,457.40 2,305,336.89 1,191,145.64 119,149.81 I'm doing something wrong here....any ideas? Thanks a bunch. Carol ===================== 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 |
|
In reply to this post by parisec
if you replace this:
numeric Tot_XN (F9.2). with this: numeric Tot_XN (comma9.2). you should get the desired result Cheers!! Albert-Jan ----- Original Message ---- From: "Parise, Carol A." <[hidden email]> To: [hidden email] Sent: Friday, January 30, 2009 2:05:24 AM Subject: String to Numeric Hi All, I have string data that look like this: 4943795 30345740 230533689 119114564 I applied this code: numeric Tot_XN (F9.2). RECODE TotX (CONVERT) INTO Tot_XN. execute. ..and got this: 4943795.00 30345740.00 230533689.0 119114564.0 11914981.00 ...It needs to look like this: 49,437.95 303,457.40 2,305,336.89 1,191,145.64 119,149.81 I'm doing something wrong here....any ideas? Thanks a bunch. Carol ===================== 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 parisec
Try this:
COMPUTE Tot_XN =number(totx, f10)/100. FORMAT Tot_XN (comma15.2). Input Result TotX Tot_XN 4943795 49,437.95 30345740 303,457.40 230533689 2,305,336.89 119114564 1,191,145.64 11914981 119,149.81 Pat -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Parise, Carol A. Sent: January 29, 2009 8:05 PM To: [hidden email] Subject: String to Numeric Hi All, I have string data that look like this: 4943795 30345740 230533689 119114564 I applied this code: numeric Tot_XN (F9.2). RECODE TotX (CONVERT) INTO Tot_XN. execute. ..and got this: 4943795.00 30345740.00 230533689.0 119114564.0 11914981.00 ...It needs to look like this: 49,437.95 303,457.40 2,305,336.89 1,191,145.64 119,149.81 I'm doing something wrong here....any ideas? Thanks a bunch. Carol ===================== 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 |
|
Thank you to Ann, Jim, and Patricia for your responses.
The syntax below worked perfectly. Carol -----Original Message----- From: Cleland, Patricia (EDU) [mailto:[hidden email]] Sent: Friday, January 30, 2009 7:49 AM To: Parise, Carol A.; [hidden email] Subject: RE: String to Numeric Try this: COMPUTE Tot_XN =number(totx, f10)/100. FORMAT Tot_XN (comma15.2). Input Result TotX Tot_XN 4943795 49,437.95 30345740 303,457.40 230533689 2,305,336.89 119114564 1,191,145.64 11914981 119,149.81 Pat -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Parise, Carol A. Sent: January 29, 2009 8:05 PM To: [hidden email] Subject: String to Numeric Hi All, I have string data that look like this: 4943795 30345740 230533689 119114564 I applied this code: numeric Tot_XN (F9.2). RECODE TotX (CONVERT) INTO Tot_XN. execute. ..and got this: 4943795.00 30345740.00 230533689.0 119114564.0 11914981.00 ...It needs to look like this: 49,437.95 303,457.40 2,305,336.89 1,191,145.64 119,149.81 I'm doing something wrong here....any ideas? Thanks a bunch. Carol ===================== 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 Cleland, Patricia (EDU)
Another question. Where does one go to find the format specifications? I
need to convert a string to 24-hr time but i can't find out which of the DATETIME formats to use. I found in a manual that DATETIME22= Day, Month, Year, 24-hr time. But what "number" of the DATETIME format is just the 24-hr time? DATETIME24, DATETIME10 ;-). Or, what if you just want to compute mm/dd/yyyy? Thanks again Carol -----Original Message----- From: Cleland, Patricia (EDU) [mailto:[hidden email]] Sent: Friday, January 30, 2009 7:49 AM To: Parise, Carol A.; [hidden email] Subject: RE: String to Numeric Try this: COMPUTE Tot_XN =number(totx, f10)/100. FORMAT Tot_XN (comma15.2). Input Result TotX Tot_XN 4943795 49,437.95 30345740 303,457.40 230533689 2,305,336.89 119114564 1,191,145.64 11914981 119,149.81 Pat -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Parise, Carol A. Sent: January 29, 2009 8:05 PM To: [hidden email] Subject: String to Numeric Hi All, I have string data that look like this: 4943795 30345740 230533689 119114564 I applied this code: numeric Tot_XN (F9.2). RECODE TotX (CONVERT) INTO Tot_XN. execute. ..and got this: 4943795.00 30345740.00 230533689.0 119114564.0 11914981.00 ...It needs to look like this: 49,437.95 303,457.40 2,305,336.89 1,191,145.64 119,149.81 I'm doing something wrong here....any ideas? Thanks a bunch. Carol ===================== 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 |
|
Depending upon the actual format of the string, you might have to do this
through separate steps from the Date/Time wizard should get you started. We'd need specific examples of what your strings contain to provide syntax. I am curious as to why all this data is coming in as strings. That is a bit strange. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Parise, Carol A. Sent: Friday, January 30, 2009 10:28 AM To: [hidden email] Subject: where to find formats Another question. Where does one go to find the format specifications? I need to convert a string to 24-hr time but i can't find out which of the DATETIME formats to use. I found in a manual that DATETIME22= Day, Month, Year, 24-hr time. But what "number" of the DATETIME format is just the 24-hr time? DATETIME24, DATETIME10 ;-). Or, what if you just want to compute mm/dd/yyyy? Thanks again Carol -----Original Message----- From: Cleland, Patricia (EDU) [mailto:[hidden email]] Sent: Friday, January 30, 2009 7:49 AM To: Parise, Carol A.; [hidden email] Subject: RE: String to Numeric Try this: COMPUTE Tot_XN =number(totx, f10)/100. FORMAT Tot_XN (comma15.2). Input Result TotX Tot_XN 4943795 49,437.95 30345740 303,457.40 230533689 2,305,336.89 119114564 1,191,145.64 11914981 119,149.81 Pat -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Parise, Carol A. Sent: January 29, 2009 8:05 PM To: [hidden email] Subject: String to Numeric Hi All, I have string data that look like this: 4943795 30345740 230533689 119114564 I applied this code: numeric Tot_XN (F9.2). RECODE TotX (CONVERT) INTO Tot_XN. execute. ..and got this: 4943795.00 30345740.00 230533689.0 119114564.0 11914981.00 ...It needs to look like this: 49,437.95 303,457.40 2,305,336.89 1,191,145.64 119,149.81 I'm doing something wrong here....any ideas? Thanks a bunch. Carol ===================== 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 |
|
I'm curious as to why my data all came in strings too. It was derived
from multiple large databases and knowing how things work here...the systems are designed so that data go in easily but getting it out is a bear. but, i thought i was receiving an actual formatted file - surprise! i had to go back and used the fixed format to import it - good times! After further review of formats from a very old SPSS manual, it appears that i may need to do this in 2 steps: Here is the string field with the 24hr time data: 0055 1543 1507 I believe that i need to do something like this: Compute Tm24=time(Tme,**). execute. FormatTm 24(time5). ...to make the data look like this: 00:55 15:43 15:07 But, i given the error i get when i run this, i know something needs to go where the ** is. I've been hunting around on Raynauld's wonderful site and haven't found this particular problem. Yet, his code for combing date fields is going to come in handy :-) Thanks Carol -----Original Message----- From: ViAnn Beadle [mailto:[hidden email]] Sent: Friday, January 30, 2009 9:55 AM To: Parise, Carol A.; [hidden email] Subject: RE: where to find formats Depending upon the actual format of the string, you might have to do this through separate steps from the Date/Time wizard should get you started. We'd need specific examples of what your strings contain to provide syntax. I am curious as to why all this data is coming in as strings. That is a bit strange. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Parise, Carol A. Sent: Friday, January 30, 2009 10:28 AM To: [hidden email] Subject: where to find formats Another question. Where does one go to find the format specifications? I need to convert a string to 24-hr time but i can't find out which of the DATETIME formats to use. I found in a manual that DATETIME22= Day, Month, Year, 24-hr time. But what "number" of the DATETIME format is just the 24-hr time? DATETIME24, DATETIME10 ;-). Or, what if you just want to compute mm/dd/yyyy? Thanks again Carol -----Original Message----- From: Cleland, Patricia (EDU) [mailto:[hidden email]] Sent: Friday, January 30, 2009 7:49 AM To: Parise, Carol A.; [hidden email] Subject: RE: String to Numeric Try this: COMPUTE Tot_XN =number(totx, f10)/100. FORMAT Tot_XN (comma15.2). Input Result TotX Tot_XN 4943795 49,437.95 30345740 303,457.40 230533689 2,305,336.89 119114564 1,191,145.64 11914981 119,149.81 Pat -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Parise, Carol A. Sent: January 29, 2009 8:05 PM To: [hidden email] Subject: String to Numeric Hi All, I have string data that look like this: 4943795 30345740 230533689 119114564 I applied this code: numeric Tot_XN (F9.2). RECODE TotX (CONVERT) INTO Tot_XN. execute. ..and got this: 4943795.00 30345740.00 230533689.0 119114564.0 11914981.00 ...It needs to look like this: 49,437.95 303,457.40 2,305,336.89 1,191,145.64 119,149.81 I'm doing something wrong here....any ideas? Thanks a bunch. Carol ===================== 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 |
|
data list list /stringtime (a4).
begin data 0055 1543 1507 end data. string #tempvar (a5). compute #tempvar=concat(substr(stringtime, 1, 2), ":", substr(stringtime, 3,2)). compute realtime=number(#tempvar, time5). formats realtime (time5). list. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Parise, Carol A. Sent: Friday, January 30, 2009 12:09 PM To: [hidden email] Subject: Re: where to find formats I'm curious as to why my data all came in strings too. It was derived from multiple large databases and knowing how things work here...the systems are designed so that data go in easily but getting it out is a bear. but, i thought i was receiving an actual formatted file - surprise! i had to go back and used the fixed format to import it - good times! After further review of formats from a very old SPSS manual, it appears that i may need to do this in 2 steps: Here is the string field with the 24hr time data: 0055 1543 1507 I believe that i need to do something like this: Compute Tm24=time(Tme,**). execute. FormatTm 24(time5). ...to make the data look like this: 00:55 15:43 15:07 But, i given the error i get when i run this, i know something needs to go where the ** is. I've been hunting around on Raynauld's wonderful site and haven't found this particular problem. Yet, his code for combing date fields is going to come in handy :-) Thanks Carol -----Original Message----- From: ViAnn Beadle [mailto:[hidden email]] Sent: Friday, January 30, 2009 9:55 AM To: Parise, Carol A.; [hidden email] Subject: RE: where to find formats Depending upon the actual format of the string, you might have to do this through separate steps from the Date/Time wizard should get you started. We'd need specific examples of what your strings contain to provide syntax. I am curious as to why all this data is coming in as strings. That is a bit strange. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Parise, Carol A. Sent: Friday, January 30, 2009 10:28 AM To: [hidden email] Subject: where to find formats Another question. Where does one go to find the format specifications? I need to convert a string to 24-hr time but i can't find out which of the DATETIME formats to use. I found in a manual that DATETIME22= Day, Month, Year, 24-hr time. But what "number" of the DATETIME format is just the 24-hr time? DATETIME24, DATETIME10 ;-). Or, what if you just want to compute mm/dd/yyyy? Thanks again Carol -----Original Message----- From: Cleland, Patricia (EDU) [mailto:[hidden email]] Sent: Friday, January 30, 2009 7:49 AM To: Parise, Carol A.; [hidden email] Subject: RE: String to Numeric Try this: COMPUTE Tot_XN =number(totx, f10)/100. FORMAT Tot_XN (comma15.2). Input Result TotX Tot_XN 4943795 49,437.95 30345740 303,457.40 230533689 2,305,336.89 119114564 1,191,145.64 11914981 119,149.81 Pat -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Parise, Carol A. Sent: January 29, 2009 8:05 PM To: [hidden email] Subject: String to Numeric Hi All, I have string data that look like this: 4943795 30345740 230533689 119114564 I applied this code: numeric Tot_XN (F9.2). RECODE TotX (CONVERT) INTO Tot_XN. execute. ..and got this: 4943795.00 30345740.00 230533689.0 119114564.0 11914981.00 ...It needs to look like this: 49,437.95 303,457.40 2,305,336.89 1,191,145.64 119,149.81 I'm doing something wrong here....any ideas? Thanks a bunch. Carol ===================== 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 ===================== 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 parisec
this is two ways to do it. open a new instance of SPSS. Copy the syntax below and paste it to a syntax page. run it. data list list/totx(a9). begin data 4943795 30345740 230533689 119114564 end data. numeric Tot_XN (comma12). RECODE TotX (CONVERT) INTO Tot_XN. compute tot_xn = tot_xn/100. compute tot_xn2 = NUMBER(totx,comma12.2). formats tot_xn tot_xn2(comma12.2). execute. LIST .Art Kendall Social Research Consultants Parise, Carol A. wrote: Hi All, I have string data that look like this: 4943795 30345740 230533689 119114564 I applied this code: numeric Tot_XN (F9.2). RECODE TotX (CONVERT) INTO Tot_XN. execute. ..and got this: 4943795.00 30345740.00 230533689.0 119114564.0 11914981.00 ...It needs to look like this: 49,437.95 303,457.40 2,305,336.89 1,191,145.64 119,149.81 I'm doing something wrong here....any ideas? Thanks a bunch. Carol ===================== 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 |
| Free forum by Nabble | Edit this page |
