"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;
set SASHELP.CARS;
where ORIGIN eq 'Asia';
data BBB;
merge AAA SASHELP.CARS;
by MAKE;
where TYPE eq 'Truck';
run;
run;
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;
x=1;
y=2;
proc print data=A;
run;
run;
You can even further simplify it by removing the data set names:
data;
x=1;
y=2;
proc print;
run;
run;
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;
set SASHELP.CARS;
where make eq 'Ford';
proc sql;
select * from A;
quit;
run;
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?
Conclusion
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
... View more