SPSS Statistics

SPSS Statistics

Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers! 

 View Only
  • 1.  Alter Type Errors

    Posted Wed October 14, 2020 09:10 PM

    I have a variable that consists of a very large number (up to 18 digits) that is in string format. I want to convert it to numeric. When I run the alter type function, some of the value convert correctly, but many convert into entirely different numbers. For example, 570100012002002104 in string format would be converted to 570100012002002110 (notice the last 2 digits are different) in numeric after running the following syntax:

    alter type stringnum (f18).

    EXECUTE.

    Has anyone encountered this or know how to accurately convert large numbers from string to numeric?

    Thank you in advance for any help!






    #SPSSStatistics
    #Support
    #SupportMigration


  • 2.  RE: Alter Type Errors

    Posted Wed October 14, 2020 10:48 PM

    Numeric values are stored as double precision floating point values. They have a mantissa of 53 bits. That allows for about 15.5 digits of precision although the magnitude can be as large as 10**308. So the string value you cite cannot be expressed exactly numerically, although the magnitude will be correct.

    This is not specific to ALTER TYPE. Any such string conversion is subject to this behavior.






    #SPSSStatistics
    #Support
    #SupportMigration


  • 3.  RE: Alter Type Errors

    Posted Thu October 15, 2020 12:30 AM

    Did not know that, thank you Jon! Is there any reliable way to convert values of this size?






    #SPSSStatistics
    #Support
    #SupportMigration


  • 4.  RE: Alter Type Errors

    Posted Thu October 15, 2020 12:30 AM

    Did not know that, thank you Jon! Is there any reliable way to convert values of this size?






    #SPSSStatistics
    #Support
    #SupportMigration


  • 5.  RE: Alter Type Errors

    Posted Thu October 15, 2020 12:56 AM

    Why do you need to convert them? What do you want to do with the numeric values? Remember that the precision loss is extremely small: at least the first 15+ digits are exact.


    You could break the string into two parts and convert them separately, but it would be awkward to work with the result.






    #SPSSStatistics
    #Support
    #SupportMigration


  • 6.  RE: Alter Type Errors

    Posted Thu October 15, 2020 04:28 PM

    We are using the numeric values as a PIN code to match across time, so we cannot have any precision loss. I don't think SPSS allows for using string variables as a key variable, so I need to convert it to numeric.


    I know, it's a crazy PIN code, but we have a massive data file so we needed a long PIN to distinguish between cases.






    #SPSSStatistics
    #Support
    #SupportMigration


  • 7.  RE: Alter Type Errors

    Posted Thu October 15, 2020 04:57 PM

    Where are you using this as a key? I would expect strings to be legitimate almost everywhere.






    #SPSSStatistics
    #Support
    #SupportMigration