BookmarkSubscribeRSS Feed
sravanece11
Calcite | Level 5
I have a macro for which input arguments are dates.
For example:
%smart("20jun2019"d)
%smart("21jun2019"d)
.
.
.
%smart("29jun2019"d)


I need to automate the above code,such that if I have start date and end date ,all the respective dates between this start and end dates should be included ,and it should happen in the above mentioned code and it should happen automatically.


Kindly help me in the automation of above mentioned code.

I tried using below code using do loop but it didn't worked


Data s;
Do i ="21jun2019"d to "29jun2019"d;
Output;
Call execute("%smart(i)");
End;
Run;
2 REPLIES 2
Reeza
Super User
That's because you're not passing I properly there, you're passing i as a text string, not the value of the variable I. Create a string with the macro call so you can see it's correct and then use call execute on the string.

str = catt('%smart(', i, ');');
output;
call execute(str);
Astounding
PROC Star

While @Reeza 's answer is the right first step, there are pitfalls galore here.  You should have an experienced macros programmer available if the results are not satisfactory.  Here are some issues to consider.

 

First (a minor issue that you could ignore), why is there any need to create a data set S?  Why not use data _NULL_ and forget about the OUTPUT statement?

 

Second, the value being fed to the macro is not a date literal.  It is the integer equivalent on SAS's date scale.  That may turn out fine, or it may not.  For example, if the value of the date is being printed in a title, the results may be need tweaking.

 

Third, executing a macro with CALL EXECUTE has its own set of pitfalls.  If %SMART contains any macro programming statements such as %LET or %DO, the results will be less than smart.  The usual fix is to modify the CALL EXECUTE statement, adding %NRSTR.  But first, see if the problem is solved.  It might be.  

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 1911 views
  • 2 likes
  • 3 in conversation