use an interative loop to avoid having to set i, etc.
do i=1 to 2;
statements;
end;
but this will output only one observation from each dataset.
There are many ways to accomplish what you want in a single data step, but it is still better to simply use two data steps since doing it in one doesn't save anything and only increases the complexity of the process.
One way is to use a single "set" statement = set dataset1(in=in1) dataset2(in=in2);
then use an "if" conditional = if in1 then do; ...; end;
Another way is to use the NOBS=N option
data _null_;
do i=1 to A+B;
if mod(i,2) then do;
set dataset1 nobs=A;
file "C:\file1.txt";
end;
else do;
set dataset2 nobs=B;
file "C:\file2.txt";
end;
...
end;
this is flawed in that if dataset1 has 5 observations and dataset2 has 12, you will get weird results or an error.
These I just thought of, and there are probably still others.
I suspect you have the wrong perspective of what SAS is.
SAS is not a process nor a machine control perspective language.
SAS is data centric.
It assumes the data is in a table, in a file and that you want to process one observation at a time. It simplifies the opening and closing of those files, their reading, writing and iteration through them.
Do not think in terms of C, Java, Pascal, COBOL, Fortran, PL/1, etc. languages which are about process or machine control.
Think instead of I have data, I want to do this with the data, waza.
The simplest thing to do in this case is
data _null_;
set dataset1;
file "C:\file1.txt";
put ... ;
run;
data _null_;
set dataset2;
file "C:\file2.txt";
put ... ;
run;
It's simple, easy to understand and easy to write, the whole point behind SAS.
doing this in one data step only confuses the issue, wastes time, provides opportunities for all kinds of errors, and is probably less efficient because of all the extra processing you have to have SAS do to keep straight what is going on.
... View more