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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.