|
I am working on developing some syntax to automatically format a data file. I have searched high and low for the syntax to define the measurement type. Right now the file comes to me with everything as a string. I need to convert about half to numeric. So for example, I want to run syntax to turn my variable FTES from string255 to numeric f16.2.
If anyone can help that would be great. Noel ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ ===================== 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 Noel
To convert string variables to numeric, the easiset way is via the autorecode command e.g. AUTORECODE VARIABLES = stringvar /INTO numvar /PRINT. The new numeric var then produces the different values of the string var as successively numbered categories, with the previous strings as the value labels for the respective cat'. You can then recode as per usual with a numeric var, and set the format to 16.2 if you want via formats numvar (f16.2). exe. cheers Chris www.figureitout.org.uk the statistical consultancy from IWP, University of Sheffield Noel wrote: > I am working on developing some syntax to automatically format a data file. I have searched high and low for the syntax to define the measurement type. Right now the file comes to me with everything as a string. I need to convert about half to numeric. So for example, I want to run syntax to turn my variable FTES from string255 to numeric f16.2. > If anyone can help that would be great. > Noel > ===================== 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 Noel-12
Hi Noel,
There are several ways to tackle this. To define measurement levels, use the VARIABLE LEVELS command, for example: VARIABLE LEVELS var1 var2 var3 (NOMINAL). However, to convert a string variable to a numeric may be a bit more complex, based on the contents of the string variable. However, the core function would likely be the NUMERIC() function. Assume for example you have a data file read from Excel, wherein a column of numbers is incorrectly defined as a string. Using SPSS you could convert the string information to numeric with the NUMBER() function as follows (assuming the following values are string characters in your data file: 4, 6, 78, 567, ...) COMPUTE num_ver = NUMBER(str_var,F8.2). I should reiterate that this can get quite complex depending on the contents of the string variable. What follows may be more information than was requested, so if uninterested, stop here; otherwise, be forewarned.. Let's assume you have a string value in the format of mm/dd/yyyy. We can read this intuitively as a date, but SPSS would be unable to do so, and therefore this "date" information would be unusable in an effort to, for example, compute length of stay or any other distance in time between a start and an end date. In addition to the NUMBER() function, you would also have to use the SUBSTR() function to parse out the day, month and year values as numbers, thus: COMPUTE month = NUMBER(SUBSTR(str_var,1,2),F8). COMPUTE day = NUMBER(SUBSTR(str_var,4,2),F8). COMPUTE year = NUMBER(SUBSTR(str_var,7,4),F8). However, keep in mind that this will still only leave you with three numeric variables, and not date information (should that be a need). To do this (and admittedly, I recognize this goes beyond your initial question, but may be useful in emphasizing my point) you would need to use a DATE.MDY() function after the above commands to parse out month, day and year, thus: COMPUTE date = DATE.MDY(month,day,year). Alternatively, a more efficient way to do this is to embed the above 3 functions when computing date, thus: COMPUTE date = DATE.MDY((NUMBER(SUBSTR(str_var,1,2),F8)), (NUMBER(SUBSTR(str_var,4,2),F8)), (NUMBER(SUBSTR(str_var,7,4),F8))). And then finally format the new date variable so we can read it: FORMATS date (ADATE8). I recognize that the above discussion addresses more than the simple answer to the initial question, but I think it underscores how complex it can get when converting string data to numeric. HTH, John Norton SPSS Inc. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Noel Sent: Thursday, May 01, 2008 11:45 AM To: [hidden email] Subject: Syntax for defining measurement type? I am working on developing some syntax to automatically format a data file. I have searched high and low for the syntax to define the measurement type. Right now the file comes to me with everything as a string. I need to convert about half to numeric. So for example, I want to run syntax to turn my variable FTES from string255 to numeric f16.2. If anyone can help that would be great. Noel ____________________________________________________________________________________ Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ ===================== 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 Noel-12
In addition to the other means mentioned, if you have SPSS 16, the simplest way to do this is to use the new ALTER TYPE command. For example,
ALTER TYPE FTES(F16.2). HTH, Jon Peck -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Noel Sent: Thursday, May 01, 2008 10:45 AM To: [hidden email] Subject: [SPSSX-L] Syntax for defining measurement type? I am working on developing some syntax to automatically format a data file. I have searched high and low for the syntax to define the measurement type. Right now the file comes to me with everything as a string. I need to convert about half to numeric. So for example, I want to run syntax to turn my variable FTES from string255 to numeric f16.2. If anyone can help that would be great. Noel ===================== 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 Noel-12
see if something like this will work in your situation.
recode var1 var3 var8 to var10, var12 to var14 . . . (convert) into numvar1 numvar3 .... formats var1 var9 var21 (dollar12.2) var13 var18 (f6.4) . . . OR compute numftes =number(ftes,f16.2). Art Kendall Social Research Consultants Noel wrote: > I am working on developing some syntax to automatically format a data file. I have searched high and low for the syntax to define the measurement type. Right now the file comes to me with everything as a string. I need to convert about half to numeric. So for example, I want to run syntax to turn my variable FTES from string255 to numeric f16.2. > If anyone can help that would be great. > Noel > > > ____________________________________________________________________________________ > Be a better friend, newshound, and > know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ > > ===================== > 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
Art Kendall
Social Research Consultants |
| Free forum by Nabble | Edit this page |
