BookmarkSubscribeRSS Feed
H
Pyrite | Level 9 H
Pyrite | Level 9

Hello,

When SAS uses the exp or log function, how many decimal places does it use for the e in the computations?

Also, does anyone know how Excel treats this same issue?

I am trying to deconstruct and replicate an online calculator for risk into a SAS program.  I believe the online calculator was originally constructed in Exel, however there is an online version as well, both always providing the same results. A student and I have been working on this project for three weeks, to near perfect success.  However, the calculator is off by a tenth of a percent for about 3% of our sample (sometimes lower or higher). The calculation is fairly long with multiple logging, exponentiations and many coefficients. I was thinking pershaps there is a difference between Excel and SAS in regards to the rounding of e in the calculations that may influence the results (account for the difference).

Also, if there is a difference in the number of decimal places and I wanted to change the number of places SAS uses in the exp or log function, can anyone propose an easy way to do this?

Thanks in advance for any help,

H.

5 REPLIES 5
jakarman
Barite | Level 11

https://support.sas.com/techsup/technote/ts654.pdf 101 numeric precision. Based on the hardware IEE IEEE floating point - Wikipedia, the free encyclopedia  binary64 double point.

Both SAS and Excel are not working with decimal places but in the digital age that is binary.

Doing some calculations in a wrong order you can easily create truncation errors that will increasingly grow. There is not notification with that.  part of how numeric processing works. Some slider experience or working with a sextant is bringing the insights.

There is an escape for that when you have a recent SAs version. You could used proc DS2 and define numeric in a decimal way. I expect problem with the scientific mathematic functions as these cannot use the hardware but must software coded versions.  

---->-- ja karman --<-----
H
Pyrite | Level 9 H
Pyrite | Level 9

I saw this online during my searches, but was hoping someone could present it to me with less jargon.

Big picture, are they different or not and how do I make them the same.  I can run a bunch of numbers in Excel and then in SAS, but this does not tell me what is happening and by chance they could appear the same even if there was a difference (due to insufficient sampling).

Thanks for enduring my ignorance!!!

H
Pyrite | Level 9 H
Pyrite | Level 9

I believe once I get a solution on places Excel uses (e.g., 15 decimals), I can then use the following

x.xxxxxxxxxxxxxxx**(x2);     => perhaps may require round function to ensure it use this

x = value in Excel

x2 an inserted number from my project

and

http://www.sascommunity.org/wiki/Tips:Calculate_logarithm_of_any_base

data show;  val=x.xxxxxxxxxxxxxxx;  b2 = log2(val);  v2 = log(val) / log(2)put b2= ;  put v2=;  run;

Though, I first still need to confirm or dismisss similarities between SAS and Excel, before figuring out the above code.

jakarman
Barite | Level 11

You are really missing how calculations are done. In the old days (some years before 1970) computers where very unusual. The calculators where to be build yet.
Doing and learning calculations you needed a slider (scientific) books with log-tables and some standard numbers with pen and pencil.
The understanding what you did with some algorithme  was necessary for getting acceptable results.  There were many good results.

The fundamentals have not changed but most people obviously do not learn those anymore. I will give you some Intel links:

- Looking for fast exponential function  (a question on using exp and got an answer with accuracy hints)

- Exponential Functions (part of intels C complier used to build a lot of software) 

good luck

---->-- ja karman --<-----
SASKiwi
PROC Star

You may find the COMPARE procedure useful when comparing numeric columns between different tables (SAS versus Excel)  that you think should be "identical".

COMPARE (using the EXACT method) will report the maximum difference found between the columns and if it is "small" it uses exponential notation to report this. If it reports the difference as 1* e(-14) or less then you know the values are essentially the same and it is floating point precision that is the culprit. If you then switch to the ABSOLUTE method, COMPARE will usually report the same columns as being identical. 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 2662 views
  • 0 likes
  • 3 in conversation