data anscombe; input set x y; cards; 1 9.9915374914 8.04 1 7.9970766529 6.95 1 13.025049202 7.58 1 8.9962624094 8.81 1 10.993954952 8.33 1 14.002129961 9.96 1 5.9973384597 7.24 1 4.0049059265 4.26 1 12.006247227 10.84 1 7.0029425145 4.82 1 5.0068786741 5.68 2 9.9818913546 9.14 2 8.0061063519 8.14 2 12.994942973 8.74 2 8.9787505152 8.77 2 11.000911976 9.26 2 13.974508468 8.1 2 5.9759214004 6.13 2 4.0139720441 3.1 2 12.000396391 9.13 2 6.9984227441 7.26 2 5.0037067232 4.74 3 10.003710589 7.46 3 8.0007401286 6.77 3 13.002322711 12.74 3 9.0074198952 7.11 3 11.013992463 7.81 3 14.01712603 8.84 3 6.0038571201 6.08 3 3.9795706367 5.39 3 11.999699396 8.15 3 6.9901001631 6.42 3 5.0131414968 5.73 4 7.9888845182 6.58 4 7.9994181791 5.76 4 7.9974345902 7.71 4 7.9991167862 8.84 4 8.0024636309 8.47 4 8.0109426831 7.04 4 8.0009609324 5.25 4 8.0081975831 5.56 4 7.9989791996 7.91 4 7.9858631803 6.89 4 18.982096098 12.5 ; i = _n_; /* _n_ is a special SAS variable */ /* it is the observation number. */ proc reg; by set; /* fit a regression separately to each set */ model y = x / r; output out = resids r = resid p = yhat cookd = d; proc plot; by set; plot d*i; /* plot Cook's D against observation number */ plot d*yhat; /* or predicted value */ title 'Cooks distance plots'; run;