Our last programming challenge is Infinitesimal in the SAS universe of discourse. The following code and the like provide a predicate to approach that “infinitesimal”:
data _null_; x=1;
do until (0=x/2);x=x/2;c+1;end;
put c= x= binary64.;
The put statement writes in the log the output:
In another word, the sas infinitesimal is .
Some programmers provided the solution by using sas contant “SMALL”. On the surface level and surprisingly, it is not the smallest number in sas universe:
data _null_;x=constant('SMALL'); y=x/2; z=x>y; put x= binary64. y= binary64. z=;run;
The rationale behind the definition of “SMALL”, from my understanding, is “SMALL” is the smallest number that the implicit bit algorithm (see IEEE 754) to encode floating point numbers is applicable.
More code to play:
data _null_; x=log2(constant('SMALL')); put x=;run;
First of all, thank Jonathan Lee, Jiangtang Hu, Jacques Thibault, Neha Mohan and Na Li for their feedback on the question about the largest 3-byte integer in sas dataset in our Code Jeet Kune Do email list. Code Jeet Kune Do is expanded from our internal Q&A mail list for technique and knowledge sharing. If you are interested to subscribe, please shoot me a message at email@example.com to add your email there.
Second, the term “infinitesimal” in the title is a bit misleading. Here is how the game is specified: Please use a program to find the minimal positive number that SAS can represent and send your code to me by August 1, 2011. The one who gets it right first wins
Hint: The following code is a brutal-force approach to pin down the maximal integer that SAS can represent.
data _null_;do until(x=x+1);x+1;end;put x= binary64.;run;
Don’t run it as I estimate it takes about 456 days to exit the loop on my laptop (unless you can access to a super super fast machine)
Jacques and I discovered an excellent paper on this subject that you can use: Numeric Length: Concepts and Consequences. This topic is along the line of the post Play Dataset Like a CS Pro: Binary Tree as it touches some fundamental issues in the field of computation.
- Best Practices (3)
- Best-Practices (16)
- BioNews (3)
- Business Best Practices (5)
- Case studies (2)
- CDISC (11)
- Clinical Data Management (6)
- Clinical Stories (1)
- Code (13)
- EDC (7)
- Event (3)
- Events (7)
- Menu (3)
- Monthly Contest (12)
- New Technologies (15)
- OpenClinica (2)
- SAS Library (4)
- Scripting (2)
- Tips & Techniques (14)
- Trends (11)