Search code examples
variablessasscientific-notation

SAS importing numeric column to scientific notation


I'm importing a sas7bdat file in sas studio using proc import and one of the variables in the dataset is changing to scientific notation, e.g, 1234567891011121 is showing up as 1.2345678E15

I'm fairly new to SAS and not sure what function would help retain this particular column in its original 16 digit format instead of scientific notation. This column is of numeric data type and its length is being displayed as 8. I have been through other similar posts, but could not find a solution to work with.


Solution

  • SAS stores all numbers as 64bit binary floating point, so using a length of 8 bytes to store the value is the right thing. You cannot use more bytes because it only takes 8 bytes to store all 64 buts. And if you used fewer bytes you would lose precision and could not store all 16 digits.

    SAS uses FORMATs to control how values are printed as text. You can use the FORMAT statement to attach a format to a variable.

    It looks like you are either using the BEST12. format with that variable, or you are letting SAS use its default way of displaying numbers, which in most cases will be to use the BEST12. format.

    If you want the numbers to print with 16 decimal digits then just attach the 16. format to the variable instead.

    Or you could use the COMMA21. format instead and the numbers will print with thousand separators so it will be easier for humans to read them.

    Example code for attaching a format to variable in a data step.

    data want;
      set have;
      format mynumber 16.;
    run;