Call Macro being generated from another macro

New User
Posts: 1

Call Macro being generated from another macro

Dear SAS community,


I had a Macro to cut every 4000 records into a new macro which later I can use them as filters in my proc sql query, my macro is as following:


%Macro test(test);

%do i=1 %to &test;


proc sql;

select distinct "'"||ID||"'" into :group&i separated by ','

from BPLCheck.padrug (firstobs=%eval(4000*(&i-1)+1) obs=%eval(4000*&i) )




%mend test;



However, while I call the &group1 and &group 2 within my proc sql query in the where statement,

where (id in (&group1) or (&group2))


SAS can not recognize those two macros. What did I do wrong? How can I make this work.


Any help is greatly appreciated.



Super User
Posts: 6,785

Re: Call Macro being generated from another macro

Posted in reply to Catherine212

When SQL creates macro variables, it creates them in the local symbol table.  But you need them to be global, so they will exist after %TEST finishes executing.  To do that, add this statement after %DO but before PROC SQL:


%global group&i;


Also note, the later WHERE statement is abbreviated.  In practice  you would be using:


where (id in (&group1) or id in (&group2));

Ask a Question
Discussion stats
  • 1 reply
  • 2 in conversation