Hi Leonid,

Your blog inspired me (not the first time) so let me share my version of the macro, which I renamed to %minclude() [from "macro include"].
The code is using DoSubL() and macro-variables-array. It also have "feature" of printing the source.
I'm going to add it to the BasePlus package (https://github.com/SASPAC/baseplus), of course adding information where the source of my inspiration came from!

Sorry for not formatted code.

All the best
Bart

/* test code */
filename f 'R:\testFile.txt';
filename f list;

%let someGlobalMacroVariable=17;

data _null_;
file f;
do i=1 to 3;
put "data y; x = " i "; run;";
put '%macro A(); %put ' i ' ** &someGlobalMacroVariable.; %mend; %A()';
end;
run;

/* macro */

%macro mInclude(
f /* sas fileref or a quoted path to the file */
,source=0
);
%local i N;
%let i = %sysfunc(DoSubL(%str(
options nonotes nosource;
data _null_;
infile &f. lrecl=32767 end=END;
input;
call symputx(cats("______", _N_), _infile_, "L");
if END then call symputx("N", _N_, "L");
run;
)));
%if 1 = %superq(source) %then
%do;
%put ++ mIncluded code: ++;
%put ;
%do i=1 %to &N.;
%put %str( +) %superq(______&i);
%end;
%put ;
%put ++++++++++++++++++++++;
%end;
%do i=1 %to &N.;
&&______&i.
%symdel ______&i /nowarn;
%end;
%mend mInclude;

/* test */
%mInclude(f)
%mInclude(f,source=1)
%mInclude('R:\testFile.txt')
%mInclude('R:\testFile.txt',source=1)