Solved
Contributor
Posts: 38

# Bug converting characters to numbers

I'm trying to convert a set of character strings into numbers, and it's not as expected.

Anyone have any ideas on how to trouble shoot?

data want;
set have;
num=input(char,best32.);
run;

Obs num char
 1 323242600026000064512 323242600026000122499 2 313244000040000684032 313244000040000698990 3 313242000020000145408 313242000020000198990 4 314245000050000134144 314245000050000159970 5 323242600026000261120 323242600026000222499 6 323242600026000261120 323242600026000222499 7 313244000040000290816 313244000040000298990 8 323242600026000064512 323242600026000122499 9 423242250022500433920 423242250022500512797 10 323245000050000134144 323245000050000171980

Accepted Solutions
Solution
‎10-27-2016 02:56 PM
PROC Star
Posts: 2,365

## Re: Bug converting characters to numbers

Assuming you are on a PC, the maximum precision that can be stored by SAS integers is 16 digits (2**53) since SAS stores numbers in 64 bits (8 bytes), and some of these are not used for the mantissa (the digits of the number). Your numbers are longer than this.

If you store real numbers, full precison is not always possible, and SAS has further issues (see https://communities.sas.com/t5/Base-SAS-Programming/Expected-numeric-precision-behaviour-or-unexpect...).

All Replies
Solution
‎10-27-2016 02:56 PM
PROC Star
Posts: 2,365

## Re: Bug converting characters to numbers

Assuming you are on a PC, the maximum precision that can be stored by SAS integers is 16 digits (2**53) since SAS stores numbers in 64 bits (8 bytes), and some of these are not used for the mantissa (the digits of the number). Your numbers are longer than this.

If you store real numbers, full precison is not always possible, and SAS has further issues (see https://communities.sas.com/t5/Base-SAS-Programming/Expected-numeric-precision-behaviour-or-unexpect...).

Contributor
Posts: 38

## Re: Bug converting characters to numbers

Thanks Chris! This was exceptionally informative and helpful.

Super User
Posts: 3,919

## Re: Bug converting characters to numbers

What do these numbers represent? Leave them as character if you are not doing mathematics on them.

Contributor
Posts: 38

## Re: Bug converting characters to numbers

Thanks SASKiwi. This was a unique problem that we ran into, and in the future we're going to restructure our coding algorithms to use character strings instead.

☑ This topic is solved.