The key is what happens when you use the OUTPUT statement in a data step. If you do not have an output statement (and do not have a DELETE or RETURN either, to be exact) SAS automatically inserts an output just before the RUN statement. If you do include an OUTPUT statement SAS assumes you do not want an automatic output so it will only output at the point where you specify. In the case of your data step, when output is specified the output takes place before the statement avrg=MEAN(OF a1-a5); At that point, there has been no calculation so avg is missing. SAS does do the calculation later, but then it is too late to include in the output data set and the result is wasted. Also, when you have an output statement inside a do loop, an output row is produced each time it passes the loop so you get 2 records for each input. SAS increments the loop variable at the end of the do loop, and then tests it to see whether it is still in the range specified. If it is not, then the loop stops. That is why i=3 (3 > 2, so stop looping) in your second dataset. If you do not drop i in your first dataset you wold have values 1 and 2 which are the values inside the loop. Regards Richard in Oz
... View more