Hi @Nietzsche
There might - as explained by others - be a use of this simple form of one-to-one reading in some special cases. I have written SAS programs since 1980, but never needed it. But it is important to know what's happening in a Data Step, and this guide exemplifies the basic behaviour of a data step including some tricky details, that might confuse a newbie, but it doesn't really explain what is going on.
Per default, a Data Step containing a SET statement performs a loop over input. When a SET statement is executed, the next observation is read into the Program Data Vector (PDV), and this continues until the last observation is read. At the end of each iteration, all variables in the PDV (with some exceptions) are written to output, and then the PDV is cleared. If the current observation is the last, the Step stops.
Now, what happens, if there are more than one SET statement? - The first SET statement reads all variables from the current input observation into the PDV. Then the next SET Statement adds all variables from the current input observation to the PDV, overwriting all values that might exist in the PDV with the same variable name. When the last observation in any of the input datasets is processed, the step stops.
So in youe example, you get Sex and Age from the Patients dataset, and ID, Height and Weight from the Measure dataset. The ID variable in the PDV is taken from Measure, because the ID already read into the PDV from Patients is overwritten. Since the ID's in the 2 input datasets are not aligned 1:1, the output is garbled, because Sex and Age comes from another ID.
The ID 9125 has correct values, because it happens to be observation 9 in both data sets, but 8125 is number 7 in the Measures dataset, but get Sex and Age from ID 4759. So the example code warns about things that could go really wrong. One might never notice the problem if there had been 11 observatiuons in both datasets. Note also, that there are only 9 observations in output, because one of the input data sets has only 9 observations, which causes the step to stop.
Common coding practice would be to use a MERGE statement instead of the two SET Statements. MERGE requires the input datasets to be sorted on the ID variable, which is used as a BY variable with the MERGE Statement in a Data Step. But there are cases where more than one SET statement is very useful, like using 2 SET Statements referring the SAME dataset, but with different starting point, to perform a look-ahead by getting values from the next observation to use in conjunction with the current observation. But then it is not a "blind" one-to-one reading as exemplified here, but controlled by different data set options, automatic end-variable and conditional execution of the second set statement.
... View more