user2280549
user2280549

Reputation: 1234

SAS - Macro calling another macro

I have a problem with SAS. More precisely with calling macro, which is inside another macro. Here is the example.

data TEST_1;
    do i = 1 to 100;
    a=i**2;
    output;
end;
run;

data TEST_2;
    do i = 1 to 100;
    b=i**3;
    output;
end;
run;

%macro macro_in(file_a);

data result1;
set &file_a;
    c=a+1;
run;

%mend;

%macro_in(TEST_1);

%macro macro_out(file_b);

data result2;
set &file_b._2;
    d=a-1;
run;

data _null_;
    do i = 1 to 2;
    call execute(COMPRESS('%macro_in(' || &file_b || '_' || i || ')'));
    output;
    end;
run;

%mend;

%macro_out(TEST);

First macro works completely fine, however there is a slight problem with variable file_b i the second macro (Code cannot use it as an argument to the inner macro). Thanks for any help!

Upvotes: 0

Views: 230

Answers (1)

dataNinja124
dataNinja124

Reputation: 130

When calling macro_in from macro_out you do not need a datastep, you can use the macro language:

%macro macro_out(file_b);

    data result2;
    set &file_b._2;
        d=a-1;
    run;

    %do i = 1 %to 2;
        %macro_in(&file_b._&i);
    %end;

%mend;

Upvotes: 2

Related Questions