<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Number conversion issue between SAS and Oracle in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/709913#M218420</link>
    <description>&lt;P&gt;You will have to talk to SAS about how their engine works. Perhaps they are letting Oracle do the transformation from DECIMAL numbers into FLOATING point and that is why you are seeing slight differences in how non-exact binary values are represented.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want simulate work with decimal numbers in SAS then store them as integers and just remember where the decimal point belongs.&amp;nbsp; You can even make your own picture format to display the integers with the implied decimal point when printing.&lt;/P&gt;
&lt;PRE&gt;177   proc format ;
178     picture mydollar low-high = '009.99' (multiplier=1) ;
NOTE: Format MYDOLLAR is already on the library WORK.FORMATS.
NOTE: Format MYDOLLAR has been output.
179   run;

NOTE: PROCEDURE FORMAT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


180
181   data test;
182     input x @@;
183     put x=  x= mydollar. ;
184   cards;

x=100 x=1.00
x=123 x=1.23
x=4567 x=45.67
&lt;/PRE&gt;</description>
    <pubDate>Thu, 07 Jan 2021 14:33:49 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-01-07T14:33:49Z</dc:date>
    <item>
      <title>Number conversion issue between SAS and Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/694906#M211975</link>
      <description>&lt;P&gt;I have encountered an issue when accessing numeric data stored in an Oracle Table in a column of type NUMBER.&lt;/P&gt;
&lt;P&gt;For a lot of numbers the retrieved value slightly differs from the one entered in Oracle. This seems to be a conversion issue between Oracle and SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following code should illustrate the issue:&lt;/P&gt;
&lt;P&gt;In Oracle DB (I use 11.2) run the following statements:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="PL"&gt;CREATE TABLE num_tmp1 (myNum NUMBER);

insert into num_tmp1 (myNum) VALUES (1.2);
insert into num_tmp1 (myNum) VALUES (6.6);
insert into num_tmp1 (myNum) VALUES (4.1234);
insert into num_tmp1 (myNum) VALUES (4.2025);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Afterwards run the following code in SAS (I use 9.4 TS1M5):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="SAS"&gt;LIBNAME O_SP2 ORACLE user="&amp;amp;user." password="&amp;amp;password." path="&amp;amp;sid.";
DATA _NULL_;
    SET O_SP2.num_tmp1;
    IF myNUM EQ round(myNUM, 0.0000001)
        THEN PUT "Works for " myNUM=;
        ELSE PUT "Works NOT for " myNUM=;
RUN;
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This results in the following log file:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;1          DATA _NULL_;
2              SET O_SP2.num_tmp1;
3              IF myNUM EQ round(myNUM, 0.0000001)
4                  THEN PUT "Works for " myNUM=;
5                  ELSE PUT "Works NOT for " myNUM=;
6          RUN;

Works NOT for MYNUM=4.2025
Works NOT for MYNUM=6.6
Works for MYNUM=1.2
Works for MYNUM=4.1234
NOTE: There were 4 observations read from the data set O_SP2.NUM_TMP1.
NOTE: DATA statement used (Total process time):
      real time           0.05 seconds
      cpu time            0.00 seconds&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I understand the issue is related to numeric conversion between Oracle and SAS. I also understand that I could change the Oracle Column Type to BINARY_DOUBLE but I really wonder if there is an SAS option that can be used (e.g. to the libname statement) to correctly convert the value between both systems.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2020 15:22:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/694906#M211975</guid>
      <dc:creator>Michael_Weiss</dc:creator>
      <dc:date>2020-10-28T15:22:08Z</dc:date>
    </item>
    <item>
      <title>Re: Number conversion issue between SAS and Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/695035#M212029</link>
      <description>&lt;P&gt;The NUMBER type is an odd data type.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. What's the precision and scale defined for that NUMBER field?&lt;/P&gt;
&lt;P&gt;2. What are the values returned?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2020 20:49:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/695035#M212029</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-10-28T20:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: Number conversion issue between SAS and Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/695094#M212054</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;mentioned, you first will need to determine the precision and scale i.e. p,s for &lt;STRONG&gt;number(p,s)&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Easiest way (without leaving SAS) is to use an explicit pass-through to access ALL_TAB_COLS in Oracle:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
connect using O_SP2 as orcl;
select * from 
connection to orcl (
	select * 
	from 
		all_tab_cols 
	where 
		owner='SCHEMA_NAME' /*&amp;lt;-- Need Schema Name*/
		and table_name='NUM_TMP1' 
		and column_name='MYNUM'
);
disconnect from orcl;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 05:27:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/695094#M212054</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2020-10-29T05:27:14Z</dc:date>
    </item>
    <item>
      <title>Re: Number conversion issue between SAS and Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/695105#M212057</link>
      <description>&lt;P&gt;Sorry for not mentioning this in my first post. NUMBER is used to store numeric values "as is" with a precision of (up to) 38 digits (See &lt;A title="Oracel Documentation for Data Type NUMBER" href="https://docs.oracle.com/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT313" target="_blank" rel="noopener"&gt;Orace Docs&lt;/A&gt;). I did not provided a scale to not allow rounding by mistake in this example.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270457"&gt;@unison&lt;/a&gt; the result of your mentioned query is NULL for pesicion and scale and 22 for length (executed directly in Oracle DB).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The actual issue happens for all types of NUMBER(p,s) e.g. NUMBER(10.4) or NUMBER(9.3) and for a lot of different numbers.&lt;/P&gt;
&lt;P&gt;NUMBER is not storing values in binary (float/double) format but in "decimal" format (two digits per byte). Therefore as long as the number looks correctly in Oracle it is stored correctly in Oracle (as I understand it). And maybe to add this in addition. The values look good in Oracle and can be retrieved correctly in Java using following code:&lt;/P&gt;
&lt;LI-CODE lang="java"&gt;Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:" + user
        + "/" + passwd + "@//" + host + ":" + port + "/" + name);

DecimalFormat NUM_FORMAT = new DecimalFormat(
        "0.##################", new DecimalFormatSymbols(Locale.ENGLISH));

ResultSet rs = con.createStatement()
        .executeQuery("SELECT * FROM num_tmp1");

while (rs.next())
{
    double val = rs.getDouble(1);
    System.out.println(NUM_FORMAT.format(val));
    double val2 = (Math.round(val * 100000)) / 100000.0d;
    if (val == val2)
    {
        System.out.println("YES: " + val + "-" + val2);
    }
    else
    {
        System.out.println("NO: " + val + "-" + val2);
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;The result of the code is as follows:&lt;/P&gt;
&lt;LI-CODE lang="java"&gt;4.2025
YES: 4.2025-4.2025
6.6
YES: 6.6-6.6
1.2
YES: 1.2-1.2
4.1234
YES: 4.1234-4.1234&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 06:58:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/695105#M212057</guid>
      <dc:creator>Michael_Weiss</dc:creator>
      <dc:date>2020-10-29T06:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: Number conversion issue between SAS and Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/695108#M212058</link>
      <description>&lt;P&gt;And what values do you get in SAS?&lt;/P&gt;
&lt;P&gt;From the second reply, where the values are correct when queried from Oracle, it seems that SAS Tech Support may need to get involved.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 07:36:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/695108#M212058</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-10-29T07:36:24Z</dc:date>
    </item>
    <item>
      <title>Re: Number conversion issue between SAS and Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/695442#M212225</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt; , you are right. I have raised a ticket with SAS support and will wait for there answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To show the difference in values I have used the following SAS program:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;LIBNAME O_SP2 ORACLE user="&amp;amp;user." password="&amp;amp;password." path="&amp;amp;sid.";
DATA _NULL_;
    SET O_SP2.num_tmp1;
    rounded=round(myNUM, 0.000001);
    PUT myNUM= 22.20 rounded= 22.20 myNUM= hex16. rounded= hex16.;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result looks as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;2          DATA _NULL_;
3              SET O_SP2.num_tmp1;
4              rounded=round(myNUM, 0.000001);
5              PUT myNUM= 22.20 rounded= 22.20 myNUM= hex16. rounded= hex16.;
6          RUN;

MYNUM=1.20000000000000000000 rounded=1.20000000000000000000 MYNUM=3FF3333333333333 rounded=3FF3333333333333
MYNUM=6.60000000000000000000 rounded=6.60000000000000000000 MYNUM=401A666666666667 rounded=401A666666666666
MYNUM=4.12340000000000000000 rounded=4.12340000000000000000 MYNUM=40107E5C91D14E3C rounded=40107E5C91D14E3C
MYNUM=4.20250000000000000000 rounded=4.20250000000000000000 MYNUM=4010CF5C28F5C290 rounded=4010CF5C28F5C28F
NOTE: There were 4 observations read from the data set O_SP2.NUM_TMP1.
NOTE: DATA statement used (Total process time):
      real time           0.05 seconds
      cpu time            0.00 seconds&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It shows that the last digit of the number displayed in HEX format differs by 1 &lt;CODE class=" language-sas"&gt;401A66666666666&lt;FONT color="#FF0000"&gt;7&lt;/FONT&gt; --&amp;gt;&amp;nbsp;401A66666666666&lt;FONT color="#FF0000"&gt;6&lt;/FONT&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a common issue when comparing calculated values, but in my case I don't do calculations.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Oct 2020 12:14:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/695442#M212225</guid>
      <dc:creator>Michael_Weiss</dc:creator>
      <dc:date>2020-10-30T12:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: Number conversion issue between SAS and Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/695808#M212375</link>
      <description>&lt;P&gt;So the SAS value is 6.6, represented as&amp;nbsp;401A666666666666.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And after you send this to Oracle, what you get back from Oracle is 6.6,&amp;nbsp;represented as 401A666666666667 ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2020 00:10:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/695808#M212375</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-11-02T00:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: Number conversion issue between SAS and Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/695843#M212398</link>
      <description>&lt;P&gt;I always get the "wrong" representation after reading from Oracle, independent of the version I send. I used the following code for testing:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA num_tmp2;
    SET O_SP2.num_tmp1;
    OUTPUT;
    mynum = round(mynum, 0.000001);
    OUTPUT;
RUN;

PROC SQL NOPRINT;
    DELETE FROM O_SP2.num_tmp1;
    INSERT INTO O_SP2.num_tmp1 (mynum) SELECT mynum from num_tmp2;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This writes all values in original (wrong) and rounded (correct) SAS representation to Oracle. Afterwards I read the values with the code from above and get the same result for both representations. In Oracle both representations are mapped correctly.&lt;/P&gt;
&lt;P&gt;I really wonder if this case is so uncommon that nobody noticed this up to now? I did some additional checks and noticed that from the numbers of the following code almost 30% get converted wrong:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA loop(KEEP=mynum);
    DO i = 0 TO 10 BY 0.001;
        mynum = round(i, 0.000001);
        OUTPUT;
    END;
RUN;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Nov 2020 08:08:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/695843#M212398</guid>
      <dc:creator>Michael_Weiss</dc:creator>
      <dc:date>2020-11-02T08:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: Number conversion issue between SAS and Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/695855#M212408</link>
      <description>&lt;P&gt;I wonder where the precision gets lost (gets even more lost I mean).&lt;/P&gt;
&lt;P&gt;According to this page&lt;/P&gt;
&lt;P&gt;&lt;A href="https://babbage.cs.qc.cuny.edu/IEEE-754.old/64bit.html" target="_blank"&gt;https://babbage.cs.qc.cuny.edu/IEEE-754.old/64bit.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;401A666666666666 is about 6.6000000000000000&lt;/P&gt;
&lt;P&gt;while&lt;/P&gt;
&lt;P&gt;401A666666666667 is about 6.6000000000000005&lt;/P&gt;
&lt;P&gt;Can you see the hex value in Oracle?&lt;/P&gt;
&lt;P&gt;Do you access Oracle via ODBC?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2020 08:42:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/695855#M212408</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-11-02T08:42:56Z</dc:date>
    </item>
    <item>
      <title>Re: Number conversion issue between SAS and Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/695856#M212409</link>
      <description>&lt;P&gt;Both values are represented in the same way in Oracle. Oracle NUMBER data type stores numbers differently, as far as I understand they store single digits (two per byte) instead of binary floating point number. I'm accessing Oracle using Java ODBC (Oracle SQL Developer).&lt;/P&gt;
&lt;P&gt;Additionally Oracle applies rounding for data types like NUMBER(10,&lt;STRONG&gt;4&lt;/STRONG&gt;), so in Oracle &lt;STRONG&gt;6.6000&lt;/STRONG&gt;&lt;EM&gt;000000000005&lt;/EM&gt; would be rounded to 6.6 anyway if column is of type NUMBER(10,&lt;STRONG&gt;4&lt;/STRONG&gt;). And the issue applies to all NUMBER columns (tested with 9,3 and 10,4).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Additionally this only applies to columns of data type NUMBER. Columns of data type BINARY_DOUBLE are not affected.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2020 09:02:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/695856#M212409</guid>
      <dc:creator>Michael_Weiss</dc:creator>
      <dc:date>2020-11-02T09:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: Number conversion issue between SAS and Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/695931#M212459</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12377"&gt;@Michael_Weiss&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm not sure, but maybe this is related to the known issue of SAS (under Windows on x64 processors) with numeric literals exceeding the precision of the internal binary floating-point representation. There was a &lt;A href="https://communities.sas.com/t5/SAS-Programming/Expected-numeric-precision-behaviour-or-unexpected-issue/td-p/287071" target="_blank" rel="noopener"&gt;long discussion&lt;/A&gt; about this (led by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;and involving responsible SAS personnel) in 2016, after which the issue was mentioned in the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lrcon&amp;amp;docsetTarget=p0ji1unv6thm0dn1gp4t01a1u0g6.htm&amp;amp;locale=de#n0pd8l179ai8odn17nncb4izqq3d" target="_blank" rel="noopener"&gt;documentation&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was reminded of that issue because you wrote that Oracle DB columns of type NUMBER "&lt;SPAN&gt;store single digits (two per byte)" and you mentioned "22 for length" and "(up to) 38 digits." Indeed, if I append a sufficient number of insignificant zeros to your example values 6.6 and 4.2025, I obtain the same slightly incorrect binary representations on my Windows workstation (see below). A similar effect also occurs with 1.2 and 4.1234, though.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
input x;
r=round(x,1e-8);
put (x r)(=hex16./)/;
cards;
1.20000000000000000000000
6.6000000000000000000000000000
4.20250000000000000000000
4.1234000000000000000000000
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Result:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;x=3FF3333333333334
r=3FF3333333333333

x=401A666666666667
r=401A666666666666

x=4010CF5C28F5C290
r=4010CF5C28F5C28F

x=40107E5C91D14E3B
r=40107E5C91D14E3C&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;In each case I used the minimum number of trailing zeros needed to cause the error (22, 27, 19 and 21, respectively). As a "rule," the internal representation fluctuates erratically between two or more slightly different values when more and more trailing zeros are appended.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please let us know when you get an interesting answer from Tech Support.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2020 13:28:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/695931#M212459</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-11-02T13:28:23Z</dc:date>
    </item>
    <item>
      <title>Re: Number conversion issue between SAS and Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/709567#M218229</link>
      <description>&lt;P&gt;Happy New Year to Everyone!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just received the answer from SAS Support that the current behavior is correct and will not be changed. We should use the round function in this case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sorry for the late reply and thanks for pointing this out, from my point of view the issue is simply because of different conversion methods between ORACLE NUMBER &amp;lt;&amp;gt; SAS DOUBLE &amp;lt;&amp;gt; Text, so likely related to the same / a similar code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 09:16:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/709567#M218229</guid>
      <dc:creator>Michael_Weiss</dc:creator>
      <dc:date>2021-01-06T09:16:02Z</dc:date>
    </item>
    <item>
      <title>Re: Number conversion issue between SAS and Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/709598#M218249</link>
      <description>"The behaviour is correct" seems an awfully terse reply. How can it be correct when the numbers differ? What makes them say the behaviour is correct? You need a better explanation than that.</description>
      <pubDate>Wed, 06 Jan 2021 11:11:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/709598#M218249</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-01-06T11:11:47Z</dc:date>
    </item>
    <item>
      <title>Re: Number conversion issue between SAS and Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/709607#M218255</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First of all, congrats on your (second) appointment as Super User of the Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;(...) How can it be correct when the numbers differ? What makes them say the behaviour is correct?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;My interpretation of the term "correct" in this particular context is:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;The internal code producing the results does what the developers intended and it has no known bugs.&lt;/LI&gt;
&lt;LI&gt;The results may seem slightly surprising at times, but they are consistent with the algorithm used and there are (good?) reasons for using this algorithm.&lt;/LI&gt;
&lt;LI&gt;The developers don't want to change the algorithm (maybe to avoid unwanted side effects) and would not regard any change as a "correction."&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12377"&gt;@Michael_Weiss&lt;/a&gt;: Many thanks for the update.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 12:54:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/709607#M218255</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-01-06T12:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: Number conversion issue between SAS and Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/709641#M218266</link>
      <description>&lt;P&gt;You are comparing apples to oranges.&lt;/P&gt;
&lt;P&gt;The Oracle system is storing the values using decimal numbers (base 10). SAS stores all numbers as floating point numbers (base 2).&lt;/P&gt;
&lt;P&gt;There are many numbers that have exact representations in base 10 that do not have exact representations in base 2.&amp;nbsp; And vice versa. So there is no real way to handle this.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In addition even for pure integers Oracle can support 22 or more decimal digits of precision and the 8 byte floating point representation SAS only allows SAS to represent integers exactly (with no gaps) to about 15 decimal digits.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2021 15:40:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/709641#M218266</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-06T15:40:58Z</dc:date>
    </item>
    <item>
      <title>Re: Number conversion issue between SAS and Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/709845#M218385</link>
      <description>&lt;P&gt;SAS knows the Oracle data type, so SAS could easily read the number as expected. A variable typed NUMBER(10,4) could easily be rounded to 4 decimals by SAS. &lt;STRONG&gt;Should be&lt;/STRONG&gt; rounded to 4 decimals, imho. That's the sole purpose of an access engine: to take care of such details.&lt;/P&gt;
&lt;P&gt;That the SAS engine doesn't do that is a defect in my world. If these details are not taken care of, and users have to fine-tune the data passed to SAS, the value of the engine decreases significantly. Also, if some values are distorted, and questions such as seen in this post arise, the trust placed in the engine is compromised.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 08:04:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/709845#M218385</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-01-07T08:04:02Z</dc:date>
    </item>
    <item>
      <title>Re: Number conversion issue between SAS and Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/709846#M218386</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt; The results may seem slightly surprising at times, but they are consistent with the algorithm used and there are (good?) reasons for using this algorithm&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Only the results count. That the algorithm is executed as expected is poor consolation if the algorithm is lacking.&lt;/P&gt;
&lt;P&gt;Also, no one likes surprises. Just do your job, Oracle engine!&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2021 08:09:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/709846#M218386</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-01-07T08:09:01Z</dc:date>
    </item>
    <item>
      <title>Re: Number conversion issue between SAS and Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/709913#M218420</link>
      <description>&lt;P&gt;You will have to talk to SAS about how their engine works. Perhaps they are letting Oracle do the transformation from DECIMAL numbers into FLOATING point and that is why you are seeing slight differences in how non-exact binary values are represented.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want simulate work with decimal numbers in SAS then store them as integers and just remember where the decimal point belongs.&amp;nbsp; You can even make your own picture format to display the integers with the implied decimal point when printing.&lt;/P&gt;
&lt;PRE&gt;177   proc format ;
178     picture mydollar low-high = '009.99' (multiplier=1) ;
NOTE: Format MYDOLLAR is already on the library WORK.FORMATS.
NOTE: Format MYDOLLAR has been output.
179   run;

NOTE: PROCEDURE FORMAT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


180
181   data test;
182     input x @@;
183     put x=  x= mydollar. ;
184   cards;

x=100 x=1.00
x=123 x=1.23
x=4567 x=45.67
&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Jan 2021 14:33:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/709913#M218420</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-01-07T14:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: Number conversion issue between SAS and Oracle</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/985001#M379777</link>
      <description>&lt;P&gt;I am aware that this discussion has been dormant for years, but I wanted to share my insights anyway.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is neither an issue with Oracle nor an issue with SAS.&lt;/P&gt;&lt;P&gt;The root cause of the discrepancy is the format in which numbers are stored in an Oracle variable with NUMBER datatype versus a SAS variable with length 8.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Oracle NUMBER datatype is a variable-length datatype. It can use up to 21 (!) bytes to store a number, but it will only use the number of bytes needed to store the number. It will store it in a decimal format though. The 21 bytes potential allows you to store a number with a very high precision (=number of significant decimal digits (not decimal places!)) in an Oracle NUMBER variable. Numbers can be stored with a precision of up to 38 (!) significant decimal digits.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS numerical variables on the other hand, are fixed-length variables (default of 8 bytes). It is evident that a variable with a limit of 8 bytes cannot store the same kind of precision as with 21 bytes. So, when Oracle NUMBER is "wav", SAS is "mp3": SAS will require less storage, and will be much faster to open and fast-forward, but not the HiFi sound that Oracle will give.&lt;/P&gt;&lt;P&gt;SAS is built to do science, it is efficient in performing complex calculations.&lt;/P&gt;&lt;P&gt;Oracle is built to store data. It is efficient in storing high precision data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, the most important difference with Oracle is that the SAS variable stores the number in the IEEE 754 double-precision (=8 byte=64 bits) format, which is a &lt;U&gt;binary&lt;/U&gt; representation of the number. As said above, it will not be able to store (all) numbers with &lt;U&gt;exactly&lt;/U&gt; the same precision (8 byte vs 21 byte).&lt;/P&gt;&lt;P&gt;If it needs to store a number which it cannot represent &lt;U&gt;exactly&lt;/U&gt; in those 8 bytes, it will store it as the number closest to it, which it can still represent in those 8 bytes.&lt;/P&gt;&lt;P&gt;The number "0.1" is a perfect example of this "floating point issue":&lt;/P&gt;&lt;P&gt;Oracle NUMBER will be able to perfectly store this value, using 2 bytes only. It is possible to do so, because it is storing the number in a &lt;U&gt;decimal&lt;/U&gt; format.&lt;/P&gt;&lt;P&gt;SAS on the other will (always) need 8 bytes, and cannot store it exactly, because SAS wants to store it in the&amp;nbsp;&lt;U&gt;binary&lt;/U&gt;&amp;nbsp;IEEE 754 double-precision format.&lt;/P&gt;&lt;P&gt;"0.1" in this format would in binary be:&lt;/P&gt;&lt;P&gt;"&lt;SPAN class=""&gt;0&lt;/SPAN&gt;&lt;SPAN class=""&gt;01111111011&lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001...&lt;/SPAN&gt;&lt;/SPAN&gt;" (with an infinite repeat of the sequence "1001")&lt;/P&gt;&lt;P&gt;SAS only has 8 byte (64bits) to its disposal, so the number cannot be represented &lt;U&gt;exactly&lt;/U&gt;. Therefore it will store an &lt;U&gt;approximated&lt;/U&gt; value, being the one closes to "0.1" which can still fit in 64 bits.&lt;/P&gt;&lt;P&gt;And no, this is not just truncating the above binary code at 64 bits. The closest 64 bit value is actually&lt;/P&gt;&lt;P&gt;"&lt;SPAN class=""&gt;0&lt;/SPAN&gt;&lt;SPAN class=""&gt;01111111011&lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1001&lt;/SPAN&gt;&lt;SPAN class=""&gt;1010&lt;/SPAN&gt;&lt;/SPAN&gt;" (ending with "10" i.o. "01").&lt;/P&gt;&lt;P&gt;In decimal notation, this is no longer exact "0.1" but it is in fact "&lt;SPAN&gt;0.1000000000000000055511151231257827021181583404541015625...&lt;/SPAN&gt;"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And this is the root cause: the Oracle NUMBER variables and SAS numerical variables are not entirely compatible because they are based on another numeral system (decimal vs binary = base 10 vs base 2).&lt;/P&gt;&lt;P&gt;You cannot write "0.1" in the form of a power of 2 (or the sum of powers of 2).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So if you import an Oracle NUMBER variable in SAS, at some point SAS will need to convert the 21 bytes in decimal notation to 8 bytes in binary notation, and it will loose precision. And there is absolutely &lt;U&gt;nothing&lt;/U&gt; you can do about that. That's just life, you'll have to live with it.&lt;/P&gt;&lt;P&gt;There is one guarantee though with the IEEE 754 double-precision format (which SAS uses): within a certain (extremely wide) range of numbers, it is mathematically guaranteed that the first 15 significant digits that you put in, will still be unchanged if you pull them out again.&lt;/P&gt;&lt;P&gt;E.g. if you insert the value "0.0012345678901234567890" (i.e. 20 significant digits) into a SAS numerical variable, if you pull it out again (e.g. for a calculation), the number that you pull out will always (guarantee) be&amp;nbsp;"0.00123456789012345###"&amp;nbsp; with the part "###" being entirely unreliable (could be empty, could be 67890, could also be 518461651861654, you simply can no longer rely on that part).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That is the reason why&lt;/P&gt;&lt;P&gt;0.3-0.2=0.1 in SAS is&amp;nbsp;&lt;U&gt;not&lt;/U&gt; TRUE.&lt;/P&gt;&lt;P&gt;0.3 will be stored as an approximated value.&lt;/P&gt;&lt;P&gt;0.2 will be stored as an approximated value.&lt;/P&gt;&lt;P&gt;0.3-0.2 will be calculated based on those approximated values, and the result will in its turn also be stored as an approximated value.&lt;/P&gt;&lt;P&gt;And 0.1 will also be stored as an approximated valued, but it will be slightly different as the approximated value above.&lt;/P&gt;&lt;P&gt;And that is why&lt;/P&gt;&lt;P&gt;0.3-0.2=0.1 in SAS is&amp;nbsp;&lt;U&gt;not&lt;/U&gt; TRUE&lt;/P&gt;&lt;P&gt;but&lt;/P&gt;&lt;P&gt;ROUND(0.3-0.2,1E-10)=0.1 in SAS &lt;U&gt;is&lt;/U&gt;&amp;nbsp;TRUE.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this explains a thing or two.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2026 11:35:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Number-conversion-issue-between-SAS-and-Oracle/m-p/985001#M379777</guid>
      <dc:creator>wmil</dc:creator>
      <dc:date>2026-03-19T11:35:49Z</dc:date>
    </item>
  </channel>
</rss>

