Another solution is to use the FILEVAR= option on the FILE statement. When writing to files on disk, FILEVAR= enables you to write to several files from one DATA step. The same is true when using FILEVAR= with DDE. It enables you to process several DDE commands from one DATA step.
Here is an example where Sheet1, Sheet2, and Sheet3 are filled with two columns and 10 rows of dummy data:
[pre]
data _null_;
do i = 1 to 3;
sheet = cats('excel|[test-sheet.xlsx]Sheet', i, '!r1c1:r10c2');
file area dde filevar=sheet;
do x = 1 to 10;
y = 2*x;
put x y;
end;
end;
run;
[/pre]
To me, this solution is simpler because there aren't any macros or macro variables involved.
Documentation for FILEVAR= option on FILE statement:
http://support.sas.com/documentation/cdl/en/lrdict/62618/HTML/default/a000171874.htm#a000699156