/* Match merge to create a sum of squares */ data a; input x id @@; datalines; 13 1 14 2 12 1 19 2 23 1 42 3 19 3 27 1 28 3 28 2 19 3 ; proc sort data=a; by id; proc means data=a noprint; by id; output out=outa; run; /* The BY statement creates alot of junk that needs cleaned up */ data outb; set outa; if _stat_='MEAN'; drop _stat_ _type_ _freq_ x; xbar=x; run; /* One more sort just to be safe */ proc sort data=outb; by id; /* Accumulate the sum of squares to create a pooled SS */ data c; merge a outb; by id; devsq=(x-xbar)*(x-xbar); ssq+devsq; *ssq may need work; proc print data=c; run; /* Same steps as above, but we will use some data step options */ /* Note that I can't drop _stat_ or the WHERE statement won't work */ /* And I keep x, even though I renamed it xbar */ data a; input x id @@; datalines; 13 1 14 2 12 1 19 2 23 1 42 3 19 3 27 1 28 3 28 2 19 3 ; proc sort data=a; by id; proc means data=a noprint; by id; output out=outa (where=(_stat_='MEAN') rename=(x=xbar) keep=id x _stat_) ; run; proc print data=outa; run;