Numeric precision in SAS. Two aspects of numeric data in SAS The first is how numeric data are stored (how a number is represented in the computer). –

Slides:



Advertisements
Similar presentations
2009 Spring Errors & Source of Errors SpringBIL108E Errors in Computing Several causes for malfunction in computer systems. –Hardware fails –Critical.
Advertisements

Computer Engineering FloatingPoint page 1 Floating Point Number system corresponding to the decimal notation 1,837 * 10 significand exponent A great number.
Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved Floating-point Numbers.
Topics covered: Floating point arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Floating Point Numbers
1 IEEE Floating Point Revision Guide for Phase Test Week 5.
Floating Point Numbers
Floating Point Numbers. CMPE12cGabriel Hugh Elkaim 2 Floating Point Numbers Registers for real numbers usually contain 32 or 64 bits, allowing 2 32 or.
Floating Point Numbers. CMPE12cCyrus Bazeghi 2 Floating Point Numbers Registers for real numbers usually contain 32 or 64 bits, allowing 2 32 or 2 64.
Signed Numbers.
Floating Point Numbers
1 Error Analysis Part 1 The Basics. 2 Key Concepts Analytical vs. numerical Methods Representation of floating-point numbers Concept of significant digits.
Floating Point Numbers
Floating Point Numbers.  Floating point numbers are real numbers.  In Java, this just means any numbers that aren’t integers (whole numbers)  For example…
The IEEE Format for storing float (single precision) data type Use the “enter” key to proceed through the show.
Binary Number Systems.
Binary Representation and Computer Arithmetic
The Binary Number System
Data Representation Number Systems.
Simple Data Type Representation and conversion of numbers
Information Representation (Level ISA3) Floating point numbers.
Computer Organization and Architecture Computer Arithmetic Chapter 9.
Computer Arithmetic Nizamettin AYDIN
1 Lecture 5 Floating Point Numbers ITEC 1000 “Introduction to Information Technology”
NUMBER REPRESENTATION CHAPTER 3 – part 3. ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3.
Computer Science 111 Fundamentals of Programming I Number Systems.
Number Systems So far we have studied the following integer number systems in computer Unsigned numbers Sign/magnitude numbers Two’s complement numbers.
Computer Architecture
ECE232: Hardware Organization and Design
Lecture Set 4 Data Types and Variables Part A – Introduction Numeric Data Types.
Data Representation - Part II. Characters A variable may not be a non-numerical type Character is the most common non- numerical type in a programming.
Floating Point. Agenda  History  Basic Terms  General representation of floating point  Constructing a simple floating point representation  Floating.
Data Representation in Computer Systems
S. Rawat I.I.T. Kanpur. Floating-point representation IEEE numbers are stored using a kind of scientific notation. ± mantissa * 2 exponent We can represent.
Computer Science Engineering B.E.(4 th sem) c omputer system organization Topic-Floating and decimal arithmetic S ubmitted to– Prof. Shweta Agrawal Submitted.
Binary Fractions. Fractions A radix separates the integer part from the fraction part of a number Columns to the right of the radix have negative.
Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.
CSC 221 Computer Organization and Assembly Language
1 Number Systems Lecture 10 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Lecture notes Reading: Section 3.4, 3.5, 3.6 Multiplication
Fractions in Binary.
Binary Arithmetic.
Data Representation: Floating Point for Real Numbers Computer Organization and Assembly Language: Module 11.
IT11004: Data Representation and Organization Floating Point Representation.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
COMPUTER SCIENCE Data Representation and Machine Concepts Section 1.7 Instructor: Lin Chen Sept 2013.
COSC2410: LAB 2 BINARY ARITHMETIC SIGNED NUMBERS FLOATING POINT REPRESENTATION BOOLEAN ALGEBRA 1.
1 float Data Type Data type that can hold numbers with decimal values – e.g. 3.14, 98.6 Floats can be used to represent many values: –Money (but see warning.
Cosc 2150: Computer Organization Chapter 9, Part 3 Floating point numbers.
CSCI206 - Computer Organization & Programming
Floating Point Numbers
Floating Point Representations
Fundamentals of Computer Science
Introduction To Computer Science
Number Systems and Binary Arithmetic
Data Representation Binary Numbers Binary Addition
Integer Division.
Numbers in a Computer Unsigned integers Signed magnitude
Data Structures Mohammed Thajeel To the second year students
Binary Numbers Material on Data Representation can be found in Chapter 2 of Computer Architecture (Nicholas Carter) CSC 370 (Blum)
CSCI206 - Computer Organization & Programming
How to represent real numbers
How to represent real numbers
CS 101 – Sept. 4 Number representation Integer Unsigned √ Signed √
Chapter 3 DataStorage Foundations of Computer Science ã Cengage Learning.
Storing Integers and Fractions
COMS 161 Introduction to Computing
Floating Point Numbers
Lecture 9: Shift, Mult, Div Fixed & Floating Point
Presentation transcript:

Numeric precision in SAS

Two aspects of numeric data in SAS The first is how numeric data are stored (how a number is represented in the computer). – Floating-Point Representation The second is how numeric data are displayed (how a number appears on a screen or piece of paper). – A format (by default or user defined)

Two aspects of numeric data in SAS Displayed ≠ Stored All displayed numeric output is formatted output, so what you see isn’t necessarily what you have. data a; a= ; run; proc print; run; obs a 1 4 By default, the format is BEST12.

Floating-point (real binary) Floating point representation is just one form of scientific notation. – The base is the number of significant digits, including zero, that a positional numeral system uses to represent the number; in this example, the base is 10. – The mantissa are the digits that define the number’s magnitude; in this example, the mantissa is – The exponent indicates how many times the base is to be multiplied; in this example, the exponent is 4.

Floating-point (real binary) Concepts – The basic unit of storage is the bit (binary digit). As the term binary suggests, there are two possible values: 0 and 1. A sequence of 8 bits is called a byte. – SAS stores numeric data using 64 bits (8 bytes). To create 64-bit output, use the BINARY64. format. – The 8 bytes are divided among 3 different types of information: the sign, the exponent, and the mantissa.

Floating-point (real binary) IEEE system (what we use in SAS) Here's the byte layout for a 64-bit number in the IEEE system used by Windows (where S = sign; E = exponent; and M = mantissa): 1 bit for the sign, 11 bits for the exponent, and 52 bits for the mantissa. The base of IEEE is 2, and the bias is The number of exponent bits determines the magnitude. The number of mantissa bits determine the precision.

Floating-point (real binary) A Example data f_point; x=255.75; put x=binary64.; run; x=

Floating-point (real binary) A Example Convert to binary, base on 2, we get normalizing the value: = *10**7 For exponent 7, add bias(1023), Convert 1030 to binary, we get For mantissa , throw away the first digit and decimal point (called implied 1 bit), Break up into nibbles (half bytes), we get x=

Numeric precision: Integer Problem: LENGTH statement data int1; length a b c 3; a=8191; b=8192; c=8193; run; data int2; length x 3; x=81933; y=81933; run;

Numeric precision: Integer Reason The 64-bit representation of 8,191: The 64-bit representation of 8,192: The 64-bit representation of 8,193:

Numeric precision: Integer Solution – The only reason to use LENGTH statement is to save disk space, and strictly follow the table below: – Try to use the COMPRESS=BINARY option instead of LENGTH (Numeric Length: Concepts and Consequences)

Numeric precision: Fraction Problem: data fra_p1; a=0.1; b=a*3; if b=0.3 then put "EQUAL"; else do; diff=b-0.3; put "UNEQUAL"; put diff=; end; run; UNEQUAL diff= E-17

Numeric precision: Fraction Reason – In the decimal number system, the fraction 1/3 cannot be precisely represented, it’s 0.333… When add 1/3 three times, it’s rather than exactly 1. – Likewise, many fractions (for example, 0.1) cannot be exactly represented in SAS data fra; fra=0.1; put fra=binary64.; run; fra=

Numeric precision: Fraction Solution ROUND(numeric-value ) Please note that the variable should be rounded to at least two decimal points more (x+2) than the comparison constant. data fra_r; a=0.1; b=a*3; if round(b,0.0001)=0.3 then put "EQUAL"; else do; diff=b-0.3; put "UNEQUAL"; put diff=; end; run; EQUAL

Other considerations Exception data ex1; length a 3; a=16384; b=16384; run; data ex2; a=0.25; b=a*10; if b=2.5 then put "EQUAL"; else do; diff=b-2.5; put "UNEQUAL"; put diff=; end; run; EQUAL

Other considerations Formula transmutation data gmt; test1=40;test2=80;test3=160;test4=320; run; data gmt1(drop=test:); set gmt; baseline=10**mean(log10(test1),log10(test2)); result=10**mean(log10(test3),log10(test4)); fold=result/baseline; diff=fold-4; fourfold=(fold>=4); run; data gmt2(drop=test:); set gmt; baseline=(test1*test2)**(1/2); result=(test3*test4)**(1/2); fold=result/baseline; diff=fold-4; fourfold=(fold>=4); run;

Conclusions Precision areas – As for integer field LENGTH statement: (3 – 8 thousand, 4 – 2 million …) – As for fraction field Storing less than 8 bytes: (would better not use LENGTH) Inexact accumulation and Comparing calculated values to constant: (use ROUND function) Tips – Avoid of using formula transmutation – When use ROUND, define the unit properly, a smaller one is preferred; do not use ROUND too early, at the last step please.