New Contributor
Posts: 2

# character to numeric conversion

Below code is auto converting value 9d10 to 9e10.It is an account id column loaded into sas from TD.In TD the value is 9d10 whereas in SAS 9E100.

data test;

x=9d10;

run;

In test dataset the value of x is shown as 9e10.Anybody has any thoughts on why this happens?

Super User
Posts: 9,799

## Re: character to numeric conversion

The reason is that the variable X, for which you supply no information, is being created as length 8 numeric variable.  Now 9d10 can be a number and can be represented as 9e10, or 9 to 10 places.  You have not said what you want the variable to be?  Maybe character (even if not, it is always good to state what type and length your varaibles are):

```data test;
length x \$20;
x="9d10";
run;```
New Contributor
Posts: 2

## Re: character to numeric conversion

Actually the data for account id is wrong in the source file itself.It should be a numeric value but is coming as a character.

More on teh background:

An XML file line is fed into a column in teradata table(used as source to SAS dataset).

In SAS that column is parsed using a macro and ACOOUNT value in xml is assigned to numeric variable ACCOUNT.

But the xml data 9d100 in TD is converted to 9e100 in sas and we are having question on why the difference in value.

My question is what is the logic behind 9d100 being converted to 9e100 as we need to explain why the value is difefrent.

ACCOUNT column cannot be converted to character as it is inherently numeric.When there is a invalid value it should be same in Teradata and source ideally.

Super User
Posts: 10,530

## Re: character to numeric conversion

Use the notdigit() function on a substring to determine if it's truly numeric before converting.

The .D... notation is mentioned in the 9.2 documentation for the Ew.d informat (which is just an alias for w.d in 9.4) as a valid numeric notation.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 8,261

## Re: character to numeric conversion

[ Edited ]

I do not understand your question. The numbers 9e100 and 9d100 are the same number. They both mean 9 times 10 raised to the 100th power.  In the old days of Fortran they used the D instead of the E to mean to use double precision (8 byte) floating point instead of single precision (4 bytes).  But in SAS all numbers are stored in 8 byte floating point.

If the field is an ACCOUNT number then you should probably be treating it as a character string in SAS. You will never need to take the mean of an ACCOUNT number.  Also there is a limit to the number of digits that an 8 byte floating point number can represent exactly.

```1     data _null_;
2       x=constant('exactint');
3       put x comma24. ;
4     run;

9,007,199,254,740,992```

Super User
Posts: 10,530

## Re: character to numeric conversion

Strings need to be marked as such, use quotes:

``````data test;
x="9d10";
run;``````
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Discussion stats
• 5 replies
• 147 views
• 0 likes
• 4 in conversation