Rezza is of course correct.
Remember, the data step is an implied loop through every record in the input datasets. If while in a DATA step loop it executes a SET, MERGE, UPDATE, MODIFY, or INPUT statement, it reads the next record into the PDV. If there is another records after the one read, it remembers that. It then progress through the rest of the data step code. If it finds an OUTPUT statement, it writes out the current record and remembers it has been written. When it hits a "run" statement (or another DATA or PROC statement if you forget the RUN), and it hasn't already been output, it outputs the record. If there are still more records from the last input dataset, it goes back to the top of the code and starts over. You can have more than one OUTPUT and it will output the record every time it sees one.
... View more