NASA's Kepler mission has discovered a world where two suns set over the horizon instead of just one. The planet, called Kepler-16b, is the most "Tatooine-like" planet yet found in our galaxy."
While catching up on my reading, this article from NASA's Kepler project fired my imagination! At last, perhaps, a glimpse of the home planet? How far away is this "Kepler 16b" anyway? About 200 light-years the article said. Unfortunately, my brain does not grok "light year" - I have no feeling for how far that would be. So, I thought, why not write the distance as something I can relate to - like meters, perhaps. Grabbing a pen and paper, I began my arduous task.
First, I looked up some values:
Then, I set about my calculations:
Distance to Tattooine = Speed of Light * Seconds In a Day * Days in a Year * 200
Distance to Tattooine = 299,792.458 * 86,400 * 365.24219879 * 200
Distance to Tattooine = 1,892,105,681,021,200,382.1696 meters
That's a LONG walk! Of course, my next thought was - "Hey, I'm a SAS Jedi! Shouldn't I be crunching numbers in SAS instead of doing it by hand?" So I decided to verify my results using this SAS program:
data _null_; HandCalculatedDistance='1,892,105,681,021,200,382.1696'; SpeedOfLight=299792458; /*M per Second*/ SecondsPerDay=86400; DaysPerYear=365.24219879; DistanceToTattooine = SpeedOfLight * SecondsPerDay * DaysPerYear *200; Difference=DistanceToTattooine-1892105681021200382.1696; PUT "NOTE: " DistanceToTattooine=comma32.4 ; put "NOTE- " HandCalculatedDistance=; put "NOTE- " Difference=; run;
And the SAS log said:
NOTE: DistanceToTattooine=1,892,105,681,021,200,384.0000 HandCalculatedDistance=1,892,105,681,021,200,382.1696 Difference=256
The actual difference was a little less than 2, but the calculated difference was 265? Crazy,right? And, I'll admit that in the grand scheme of things the difference between the distances was VERY small, but it really bugged me. So back to the Internet I went, and found this excellent blog entry by Chris Hemedinger titled "Numbers great and small: the problem of Big Datum". That reminded me of the benefits and drawbacks of using floating point representation for numeric values, and the limitations imposed by storing those numbers in 8 bytes. I guess it's time for a Jedi SAS Trick!
DS2 is a new DATA step-like programming language which is available experimentally in SAS9.3, and will be a fully production part of BASE SAS9.4. DS2 brings some amazing abilities to SAS, one of which is processing datatypes other than the standard fixed-width character / double-precision floating point numeric. If you license BASE SAS9.3 or SAS9.4, you can try out my new solution, too! I wrote and ran my code in a pre-production version of SAS9.4. There are some great benefits to being a SAS employee :-)
This DS2 program will verify my results:
proc ds2; data _null_; dcl decimal(50,10) SpeedOfLight SecondsPerDay DaysPerYear Difference HandCalculatedDistance DistanceToTattooine; method init(); HandCalculatedDistance=1892105681021200382.1696n; SpeedOfLight=299792458n; /*KM per Second*/ SecondsPerDay=86400n; /*Seconds per day*/ DaysPerYear=365.24219879n;/*Seconds per year*/ DistanceToTattooine = SpeedOfLight * SecondsPerDay * DaysPerYear *200n; Difference=DistanceToTattooine-HandCalculatedDistance; PUT 'NOTE: ' DistanceToTattooine=; put ' ' HandCalculatedDistance=; put ' ' Difference=; end; enddata; run; quit;
And my SAS log clearly shows that my hand calculations were just fine:
NOTE: distancetotattooine=1892105681021200382.1696000000 handcalculateddistance=1892105681021200382.1696000000 difference=0.0000000000
Nice!! Want to learn more about SAS DS2? I'm presenting a pre-conference workshop titled "What will DS2 do for You?". Perhaps I'll see you there?
Until next time, may the SAS be with you!