data result (keep=mean_a_dif mean_b_dif);
retain mean_a mean_b;
set ahuige end=last;
total_a+a;
if not missing(a) then num_a+1;
total_b +b;
if not missing(b) then num_b+1;
if _N_=&k. then do;
mean_a=total_A/num_a;
mean_b=total_b/num_b;
total_a=0;
num_a=0;
total_b=0;
num_b=0;
end;
if last then do;
mean_a_dif=mean_a-total_a/num_a;
mean_b_dif=mean_b-total_b/num_b;
output;
end;
run;
%let k=2;
data ex(keep=ma mb);
set ahuige nobs=n;
if &k. ge _N_ then
do;
aa1+A;bb1+B;
if missing(A) then missa1+1;
if missing(B) then missb1+1;
end;
else do;
aa2+A;bb2+B;
if missing(A) then missa2+1;
if missing(B) then missb2+1;
end;
if _N_=n then
do;
ma=aa1/(&k.-missa1)- aa2/(n-&k.-missb1);
mb=bb1/(&k.-missa2)- bb2/(n-&k.-missb2);
output;
end;
run;[/code:3que81hy]
proc sql ;
select mean(a), mean(b) into :ma1, :mb1 from ahuige where monotonic() le &k.;
select &ma1.-mean(a),&mb1.-mean(b) into :ma,:mb from ahuige where monotonic() gt &k.;
quit;[/code:3uuadprv]