"Unpredictable" certainly was the incorrect choice for a word, because SAS
is always predictible if you know everything. But then if you knew
everything, you wouldn't need to write a SAS program to analyze the data!
HOWEVER, I would still stray away from using multiple SET statements in the
same data step for the following reasons:
1) Observations from the end of one or more input data sets will be
deleted from the output data set unless all input data sets have the same
number of observations.
2) Combining several data sets into one data set with multiple SET
statements mimmicks a merge, but each input data step may not be in sorted
order and is not required to be in sorted order.
3) Combining several data sets into one data set with multiple SET
statements mimmicks a merge, but each input data step may not have matching
keys (even if it is in "sorted" order).
4) Combining several data sets through one data step and out to multiple
data sets runs the risk of multiplying the issues above.
5) From my experience, the intent that most users have in mind when using
multiple SET statements in the same data step is better and more
efficiently resolved using MERGE statements, PROC SQL. and/or other data
6) Multiple SET statements in one data step could lead to the overwriting
of variables with the same name, rather than appending new records
(or "creating" new records) as when several data sets are used in one SET
statement. No warning will occur in the log if this happens.
7) If any of the SET statements are inside a condition, then the value of
the last record read will be retained for the remaining records until the
first time one of the input data sets encounters the end-of-data marker.
8) If one of the SET statements declares a data set with zero records,
then the resulting data set output will provide the n-1 records from the
iteration in which the "zero-record" data was called (it could be
9) The SET statement wasn't designed to occur more than once in a data
step. Just because it CAN be done does not mean that it SHOULD be done.
10) Multiple SET statements in one data step are confusing, outside
standards, and overly challenging to support in production code.
Of course, the aforementioned "IF _N_=1 THEN SET" routine is an exception
that is well-documented and supported by SAS, and I would exclude it from
these 10 points.
And, I suppose, someone could come up with a practical use for these issues
and call it a "feature" ...
However, I recommend avoid it.
Free SAS Tutorials and Newsletter