I am able to run that macro by manually putting multiple values for macro variables. but not able to loop macro variable values automatically.
for eg:
%let dt = 201901
%let dt = 201902
%let dt = 201903
%let dt = 201904
but I want it like to be resolved automatically each time of invocation.
@kajal_30 wrote:
I am able to run that macro by manually putting multiple values for macro variables. but not able to loop macro variable values automatically.
for eg:
%let dt = 201901
%let dt = 201902
%let dt = 201903
%let dt = 201904
but I want it like to be resolved automatically each time of invocation.
????
Define the macro to take a PARAMETER.
Then when you CALL the macro pass in the value for the PARAMTER.
%macro mymacro(dt);
.... &DT ....
%mend mymacro;
%mymacro(dt=201901)
%mymacro(dt=201902)
...
Or use a data step to call it multiple times.
So to call it with the 6 months starting 01JAN2019 you might use a data step like this.
data _null_;
basedate='01JAN2019'd;
do offset=0 to 5 ;
date=intnx('month',basedate,offset);
call execute('%nrstr(%mymacro)(dt=' || put(date,yymmn6.) || ')' );
end;
run;
Then either your macro is more complex than you have shown or you are doing other steps between the macro calls when you are running it manually.
I think the problem is likely in the attempt to use CALL EXECUTE.
The macro looks like it should work to me. It writes (and over-writes) work.&out_table, then at the end PROC APPENDS it to out.&out_table. It's bad style / risky to overwrite work.&out_table, but I think it should work when called three times in a row, including using CALL EXECUTE to generate the macro calls.
Using PROC APPEND with dataset generated from PROC IMPORT is another source of errors as you cannot depend on PROC IMPORT creating compatible dataset structures. But they would happen whether or not any code generation (macro call or CALL EXECUTE() function calls) was used to run the steps.
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 25. 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.