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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 17 replies
  • 2118 views
  • 9 likes
  • 6 in conversation