shecode
shecode

Reputation: 1726

How to use a macro parameter to call another macro in SAS

I'm finding a lot of my macro jobs have a similar structure. To make my code tidier i'd like to make a generic macro where I have three inputs, the first date of when I run the job. The number of dates to run it for, and the name of the macro that I want to execute for these dates

Below is my code, it works if I hardcode the macro within the run_dates macro, but I can't call it using a macro variable passed as a parameter. How can I use a macro variable passed as a parameter to call another macro?

I've added comments into the code where it doesn't work. i've simplified the outputs so they dont look interesting or logical but what i'm looking for is just to be able to use that macro variable.

%macro test_macro(dt);
%put macro date is &dt;
%mend test_macro;



%macro run_dates(dt_start, num, macro_name);

%put &macro_name;

%do i =0 %to &num ; 

    data _null_;
        call symput('querydate',"'" || put(intnx('month',&dt_start.d ,&i,'e'),date9.) || "'");
    run;

    %put prepaid daily for &querydate;

    /*this is where I want to call the macro*/
    %&macro_name(&querydate);

%end;

%mend run_dates;

/*now run the main macro*/
%run_dates('03jun2012', 10,'test_macro');

Upvotes: 0

Views: 672

Answers (1)

stallingOne
stallingOne

Reputation: 4006

just remove the quotes from macro_name

%run_dates('03jun2012', 10,test_macro);

Upvotes: 2

Related Questions