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!
Mark

Share

Principal Technical Training Consultant

Mark Jordan (a.k.a. SAS Jedi) grew up in northeast Brazil as the son of Baptist missionaries. After 20 years as a US Navy submariner pursuing his passion for programming as a hobby, in 1994 he retired, turned his hobby into a dream job, and has been a SAS programmer ever since. Mark writes and teaches a broad spectrum of SAS programming classes, and his book, "Mastering the SAS® DS2 Procedure: Advanced Data Wrangling Techniques" is in its second edition. When he isn’t writing, teaching, or posting “Jedi SAS Tricks”, Mark enjoys playing with his grand and great-grandchildren, hanging out at the beach, and reading science fiction novels. His secret obsession is flying toys – kites, rockets, drones – and though he usually tries to convince Lori that they are for the grandkids, she isn't buying it. Mark lives in historic Williamsburg, VA with his wife, Lori, and Stella, their cat. To connect with Mark, check out his SAS Press Author page, follow him on Twitter @SASJedi or connect on Facebook or LinkedIn.

• Jianfeng,

DS2 integrates the power and process control of the traditional SAS DATA step with the flexibility and rich data type palate of SQL. Because DS2 is a next-generation DATA Step language of sorts, I'm under the impression that the name came from "DATA Step 2". Calling it DS2 makes it easier to talk about the two languages while making a clear distinction between them.

There are several important differences between the two languages. Some of the most noticeable differences include:
1. DS2 works only with structured data while the traditional DATA step can read unstructured (raw) data.
2. DS2 can simply and safely process observations in parallel while the traditional DATA step only processes records sequentially.
3. DS2 easily facilitates object-oriented application design, which is not really an option with the traditional DATA step.

It's best to think of DS2 and the traditional DATA step as complimentary programming languages, much as Macro, DATA step and SQL have complimented each other for years in the SAS ecosystem. The traditional DATA Step language is mature, efficient and still under significant development, and will be around for many years to come. DS2 is a more flexible and user-extensible language, and I'm sure it will provide some new and amazing "superpowers" in the years to come :-)

I hope this answers your question. May the SAS be with you!
Mark

1. Can you explain why the difference I traditional SAS? - maybe an example can help others who like me do not quite understand the reason (or how SAS stores decimal numbers I guess)

• Key difference: DS2 runs external to the MVA SAS process. The architecture of DS2 enables data step execution in multiple threads. Addition of the SAS Code Accelerator for product to you SAS/Access license enables DS2 programs to compile and execute completely in-database, minimizing data movement and leveraging the native massively parallel processing architecture of the RDBMS. SAS9.4 will include SAS Code Accelerators for Greenplum and Teradata, with others soon to follow. The performance boost for compute-intensive data manipulation is quite impressive.

At the core, DS2 uses DATA step-like syntax:
DATA and SET statements
IF...THEN...ELSE
Arrays
DO loops
BY groups
FIRST. and LAST. processing
Expressions and Functions

But DS2 DATA Step is clearly different from the Base SAS Data step:
Does not read/write raw data files (No INFILE, INPUT)
Intersects DATA step with with SQL1999 (accepts in-line SQL query on the SET statement)
Modern programming structures (Methods, Packages, variable scoping within a DATA step)

Stay SASy, my friend!
Mark

2. Mark Jordan on

I presented a pre-conference workshop titled "DS2 and You" at SAS Global Forum this year. If you want, you can download the materials from http://marksworld.net/free/DS2andYou.zip. The ZIP file contains a PDF of the presentation, sample data and code.

May the SAS be with you!
Mark

• This was definitely a must to see. I thoroughly enjoyed it. Thanks, again, Mark Planets Pivotal and TeraData down (in 9.4 that is), on to Netezza

• Hi Mark, thanks for sharing your presentation materials. I just downloaded them, but the copy that was on the website does not contain the PDF of the presentation. Is it possible that the PDF was removed for some reason? Thanks!

Carl

3. I wanted to be the first to comment on such an awesome post. I loved it!

Oddly enough, when I read "DS2" I keep thinking of DS9 (Deep Space Nine). The force may be with you, but perhaps there is some Trekkie in you too?

• Jared, thanks for your feedback on the post :-)

I was raised in northeast Brazil (my parents were Baptist missionaries there). When I finally came home to the US to stay in 1969, we arrived a couple of weeks before Neil Armstrong's famous "one small step". Needless to say, I was glued to the TV! And even though I missed seeing Star Trek during it's original run, I got hooked on it in the 70's.

I may be a SAS Jedi, but Jedi are diplomats as well as warriors, striving to be well-versed in the customs of many cultures. So I can freely admit that I am quick to return a Vulcan salute, and can even respond properly to the traditional Vulcan greeting "Live long and prosper" with the proper reply: "Peace, and long life".

May the SAS be with you!
Mark