please help for solution
Let's breakdown the assignment into parts:
macro function %countdown
Sounds like they want to to define a SAS macro named COUNTDOWN. Do you know what statement that is?
It is strange that they used the term FUNCTION here. Are they trying to say that the macro only generates part of statement so that it can be used in the middle of a statement or expression, like you would use an actual SAS function call?
having a numeric parameter
SAS parameters are macro variables (or they become macro variables that local to the macro). And macro variables always contain text. I think they mean here that the macro will expect the parameter values to be text strings that SAS code would interpret as numbers. Like 10.
and producing the following output in the log :
Countdown 10...
Countdown 9...
Countdown 8...
Countdown 7...
Countdown 6...
Countdown 5...
Countdown 4...
Countdown 3...
Countdown 2...
Countdown 1...
BOOM !!!
Sounds like they want it to ignore the input parameter and always start the countdown at 10. But let's assume that they really wanted the countdown to start with the value of the input parameter.
You have an answer for a macro that uses a %DO loop.
How do you think you could do it with recursion?
Do you know what recursion is?
Do you know how to program recursion? Hint: make sure that there is a way to prevent the recursion from going on forever.
When done compare to this:
%macro countdown(start);
%if &start > 0 %then %do;
%put Countdown &start;
%countdown(%eval(&start-1))
%end;
%else %put BOOM !!!;
%mend countdown;
Thank you TOM
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.