This is a long thread, and I am jumping in late, but I highly recommend the solution by @RW9. You want to use PROC MEANS or PROC SUMMARY to do the computation of statistics across groups, that is one of the features of PROC MEANS/PROC SUMMARY, plus it handles missing values properly, plus it has been tested, debugged and validated in a bazillion, 408 thousand and three real-world applications.
You do not want to write your own data step code to compute group means. Not only is this unnecessarily time consuming to write and test this code compared to using the features in PROC MEANS/PROC SUMMARY, but writing your own code also runs the risk of bugs and incorrect answers (which is not the case with using PROC MEANS/PROC SUMMARY).
@RW9 wrote:
Right, so do the means step, then set that with your data e.g.
proc means data=vs;
class pt;
var result;
output out=want mean=mean;
run;
data vs;
set vs (in=a) mean (in=b);
if b then flag="Y";
run;
... View more