BookmarkSubscribeRSS Feed
Lapis Lazuli | Level 10

einstein-banner.jpg                                                                                         "Creativity is intelligence having fun"

                                                                                                                       ~ Albert Einstein


The last time I checked, April Fools' Day has not been cancelled this year. Moreover, we all desperately need it as it is scientifically proven that laughter is an immune booster.


No kidding, laughing is a serious matter. That is why today we are going to get serious, very serious, and tackle the most famous and the least understood scientific theory of all time – the theory of relativity – as it relates to programming in general, and SAS programming in particular.


Fasten your seat belt!


Any computer program can be described in terms of space and time.  For example, SAS code originates in our 3-dimensional heads’ space, transforms into a two-dimensional space entity in a Program Editor, and then progresses through compilation to execution in a one-dimensional time line sequence defined by itself and multi-dimensional SAS computational space also known as infrastructure. This introduces a fundamental concept of relativity theory – spacetime as a unified entity of space and time.


Creative use of the spacetime principle opens unlimited possibilities for SAS code developers. For example, you can embed a DATA step within another DATA step or a PROC step and vice versa.  You just need to apply the appropriate spacing to ensure your code has proper readability.


The theory of relativity consists of two interrelated parts: special relativity and general relativity.


Special Theory of Relativity


Special relativity applies to all coding methods in the absence of gravity. Consider running the following SAS code:

data AAA;
   where ORIGIN eq 'Asia';
   data BBB;
      merge AAA SASHELP.CARS;
      by MAKE;
      where TYPE eq 'Truck';

While it might seem unusual, this is perfectly legitimate code that 1) does not mention gravity and 2) runs without ERRORs. As you can see, the code for data BBB step is totally embedded within the data AAA step, and it even recursively merges its parent data AAA within itself. If you think about it, it’s pure spacetime – a combination of proper code spacing and timing of execution.


Or, you may want to try this code where PROC PRINT is nested within a DATA step and prints its parent data set:

data A;
   proc print data=A;

You can even further simplify it by removing the data set names:

   proc print;

It still runs perfectly fine and as expected, even though no data set names are specified.

Here is another beauty where PROC SQL is embedded within a DATA step and recursively reads its own parental data:

data A;
   where make eq 'Ford';
   proc sql;
      select * from A;

The above examples are possible due to coding relativism – the idea that views are relative to differences in perception and consideration. What you see in a SAS program may be different from how the SAS compiler sees and interprets it. Moreover, as you will find below, what you consider as program code could be construed and interpreted as data, and vice versa.


General Theory of Relativity


General relativity applies to objects and methods in the presence of gravity and explains its relation to other objects and methods. It is general relativity that deals with such eminent phenomena as black holes: regions of spacetime exhibiting gravitational acceleration so strong that nothing, I mean, nothing – no objects, particles or even electromagnetic radiation such as light – can escape from it.


The following code example illustrates the concept of a black hole as it relates to SAS programming:

; %let time = LINE      ;
; %let s=%length(&TIME) ;
; data B                ;
;    input              ;
;    TYPE = 'Gravity'   ;
;    &time.s&s          ;
;    data A             ;
;       TYPE = 'Light'  ;
;    run                ;
; run                   ;

The code is very similar to the ones above it, but as you can see, we did introduce gravity in it. If you dare to run it, you will see that the embedded DATA step (data A)  is prominently absent from the SAS LOG, not to mention that it never runs. Typical black hole: we know it exists, but no one can see it in action.


This can only be explained by such a strong gravitational pull of the data set B that nothing can escape from it, precisely the definition of a black hole.  Can you provide your explanation?




I hope by now you are convinced that a combination of spacing and timing can produce quite remarkable effects making your SAS code unbelievably elegant and nerdy at the same time. (The degree to which it’s elegant or nerdy is relative to your attitude, perception and consideration.)


I am optimistic that after reading and sifting through these theoretical fundamentals and coding examples you will reach beyond your traditional thinking, discover your fourth dimension and come up with your own code masterpieces that are related to the relativity theory.


Please share your thoughts and ideas below.


Additional resources


April 1, 2019: Dividing by zero with SAS

April 1, 2018: SAS discovers a new planet in the Solar System

April 1, 2017: SAS code to prove Fermat's Last Theorem

Tourmaline | Level 20


My mind is blown.

So much cleverness condensed in such little space!

Almost like a white dwarf.

Thank you!

Lapis Lazuli | Level 10

Thank you, ChrisNZ !

Here is your white dwarf:

data _;
   if 0;



Community Manager

It's also been established that the faster that you write SAS code -- as your coding activity approaches the speed of light -- the slower that you will age relative to programmers who use other languages.


(Or is it the other way around? I forget things in my old age.)

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
Lapis Lazuli | Level 10

, the speed of your SAS code writing and your age are irrelevant, as long as you know how to use CALL EXECUTE to write SAS code for you .  Or you can even let SAS write batch scripts for you .

Onyx | Level 15

Wasn't it: "the faster you're coding the slower it's running"? 😉 😉

All the best
Polish SAS Users Group: and

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation

Obsidian | Level 7

Great post as always, Leonid!  Thanks for sharing!


Be safe and stay healthy!



Lapis Lazuli | Level 10

Thank you, Kirk. I am glad you like it. Hope you and yours are safe and healthy too!

Obsidian | Level 7


Thanks for another creative April 1 post! The laughs are both generally and relatively timely.


Lapis Lazuli | Level 10




SAS Employee

Awesome Leonid!  That was funny and enlightening.  That's a tough balance to strike.

Lapis Lazuli | Level 10

Thank you, wrrichar1!

Yea, I felt like a tightrope walker balancing over the abyss of reality...

Meteorite | Level 14

Great post @LeonidBatkhan!

I smiled at the statement you made "What you see in a SAS program is different from how the SAS compiler sees and interprets it."... when I used to teach SAS programming classes I would emphasise the importance of reading SAS code like the compiler would interpret it. Look for the tokens (or missing tokens) and challenge yourself to see what would happen behind the scenes before you run it. In my book, it distinguishes oneself from "doing" SAS programming to "being" a SAS programmer. Anyone can copy/paste code and try to work it out with debugging/troubleshooting but knowing how the code works and what the code will do before you run it, demonstrates a higher level of understanding and being an efficient SAS programmer.

//Contact me to learn how Metacoda software can help keep your SAS platform secure -
Lapis Lazuli | Level 10

Thank you, MichelleHomes, I am glad it made you smile. Your point is exactly what I exploited here. 😜

SAS Employee

so beautifully articulated. thank you for sharing these amazing tips on relativity in sas code.


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