Recursion is a powerful tool.
It can also be very slippery and should very carefully document exactly what the inputs are expected to be.
For example this particular macro will generate an error if called with a decimal value such as
%put %mysum(2.1);
You may find if you test that option that you have an unstable system as well because of the way that SAS treats macro code.
Calling the macro this way:
%put %mysum(2);
%put %mysum(2.1);
%put %mysum(2);
Generates this log:
6 %put %mysum(2);
mysum called: n=2
mysum called: n=1
3
7 %put %mysum(2.1);
mysum called: n=2.1
ERROR: A character operand was found in the %EVAL function or %IF
condition where a numeric operand is required. The condition was:
2.1-1
ERROR: The macro MYSUM will stop executing.
ERROR: A character operand was found in the %EVAL function or %IF
condition where a numeric operand is required. The condition was:
2.1 +
ERROR: The macro MYSUM will stop executing.
8 %put %mysum(2);
ERROR: Open code statement recursion detected.
Moral of the story: If you pursue this then SAVE YOUR CODE frequently as it easy to place SAS into an unstable session. That open code recursion error usually means time to stop and restart SAS.
Another concern with recursion is setting a stopping rule. It is very easy to create an infinite loop if your stop condition is poorly designed.
... View more