data a; input x @@; datalines; 23 34 15 17 19 22 ; run; proc means data=a; var x; output out=outx; run; /* Inspect outx to look at the output data file */ data b; input x id @@; datalines; 23 2 34 2 15 1 17 1 19 1 22 2 ; run; proc sort data=b; by id; run; proc means data=b; by id; var x; output out=outxid; /* Inspect outxid to see how BY groups are handled */ run; data c; set outxid; if _stat_='MEAN'; /* Clean up the data set a little */ xmean=x; drop _stat_ _type_ _freq_ x; proc print data=c noobs; run; /* Save only the sample means; we could then use a many-to-one merge */ /* to link the data with their appropriate ID mean */ * Here is more efficient alternate code for saving only the mean; proc means data=b; by id; output out=outxid (drop=_type_ _freq_) mean(x)=xmean ; /* Inspect outxid to see how BY groups are handled */ run; *Less efficient than above without DROP option; data c; set outxid; /* Clean up the data set a little */ drop _type_ _freq_; proc print data=c noobs; run;