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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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