使用 Proc MEANS 同 BY 和 OUTPUT 声明。
Proc MEANS
BY
OUTPUT
data have; rownum = 0; do rowid = 1 to 1000; subjectid + 1; do measurenum = 1 to 6; do repeat = 1 to ceil(4 * ranuni(123)); array flags flag1-flag999; do _n_ = 1 to dim(flags); flags(_n_) = ranuni(123) < 0.10; if subjectid < 7 and measurenum = subjectid then flags(_n_) = .; end; rownum + 1; output; end; end; end; keep rownum measurenum subjectid flag:; run; proc means noprint data=have; by subjectid measurenum; var flag:; output max=; run;