Search code examples
sassas-macroproc-sqldatastep

How to use a SAS Macro inside data step


I'm running a code similare to the following one and the data step is not working and I can't seem to understand why

%macro macro_1(variable);
rsubmit;
data want_&variable. (keep = a b c);
set have;
run;
endrsubmit;
%mend macro_1; 


%macro testing;
%do i=1 %to 3;
%macro_1(&i.); /* My loop here*/
%end;
%mend testing;

%testing;

Here's the error I keep on getting :

Syntax error, expecting one of the following: a name, a quoted string, (, /, ;, DATA, LAST, NULL.

I have tried using the double ampersand or using more periods at the end, unsuccessfully however

Much thanks for any help !


Solution

  • You have defined the macro variable VARIABLE on the local machine, but the code that is using the macro variable is running on the remote machine. Try pushing the value to the remote machine before trying to use it.

    %macro macro_1(variable);
    %syslput variable=&variable;
    rsubmit;
    data want_&variable. (keep = a b c);
    set have;
    run;
    endrsubmit;
    %mend macro_1;