The question is: can you define the name of a SAS data set at runtime?
I think it will be difficult to use a macro to do this because the names of the data sets aren't known until runtime, whereas the macro language is a preprocessor that substitutes code before the proc is run.
Defining the name of a SAS data set at runtime is simple in SAS/IML Studio, since you can use expressions for I/O statements such as the CREATE statement:
/* The following example runs in SAS/IML Studio, but not PROC IML */
A = {0};
do i = 1 to 3;
A = A || i;
DSName = "test_" + strip(char(i));
create (DSName) from A;
append from A;
close (DSName);
end;
In PROC IML, you can to use the EXECUTE statement to define the name of the data set at run time:
/* Similar idea; runs in PROC IML */
proc iml;
start WriteMatrix(a, DSName);
CreateStmt = "create " + DSName + " from A;";
CloseStmt = "close " + DSName + ";";
call execute(CreateStmt);
append from A;
call execute(CloseStmt);
finish;
A = {0};
do i = 1 to 3;
A = A || i;
DSName = "test_" + strip(char(i));
run WriteMatrix(A, DSName);
end;