SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pavank
Quartz | Level 8

please help for solution 

Tom
Super User Tom
Super User

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:

 

Spoiler

 

%macro countdown(start);
%if &start > 0 %then %do;
  %put Countdown &start;
  %countdown(%eval(&start-1))
%end;
%else %put BOOM !!!;
%mend countdown;

 

 

 

 

 

BrahmanandaRao
Lapis Lazuli | Level 10

Thank you TOM

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 17 replies
  • 3245 views
  • 9 likes
  • 6 in conversation