You are calling the macro in the middle of a DATA step. That means the only SAS statements the macro can generate are statements that can be used to construct a data step. Like an assignment statement, INPUT, PUT, FORMAT, LABEL, LENGTH etc.
But you macro is generating a complete data step, include another DATA statement.
So your SAS code ends up looking like this:
data _null_;
set filenames3;
if _n_=&i then do;
DATA IMPORT_OSA_&ORDER.;
infile "/sasdata/it_databases/myFile_20211207_&EXTENSION...txt" dlm=';' dsd missover;
input
var1 : $CHAR3.
var2 : $CHAR2.
var3 : $CHAR5.
var4 : ?? BEST6.
;
run;
end;
run;
So the DO statement in the outer data step never has an END statement. Instead you started another DATA step.
It really looks like you are just trying to read ALL of the files in a directory.
Why not just do that directly and skip all of the other rigamarole?
data IMPORT_OSA ;
infile "/sasdata/it_databases/*.txt" dlm=';' dsd truncover ;
length var1 $3 var2 $2 var3 $5 var4 8;
input var1-var3 var4 ?? ;
run;
... View more