data example9_8;
input id test y;
dif=test-y; 
mean=(test+y)/2;
cards;
1	-2.10 	-2.50 
2	-2.50 	-2.05 
3	-1.95 	-0.75 
4	-4.45 	-1.65 
5	-3.25 	-1.55 
6	-1.75 	-1.55 
7	-0.35 	-0.20 
8	-1.70 	-0.90 
9	-3.05 	-1.90 
10	-4.60 	-3.25 
11	-2.25 	-1.75 
12	-2.40 	-2.90 
13	-3.95 	-3.10 
14	-1.95 	-0.65 
15	-1.25 	-2.10 
16	-2.20 	-0.65 
17	-1.75 	-1.40 
18	-3.30 	-4.10 
19	-4.95 	-2.10 
20	-0.95 	-0.55 
;
/*步骤1：产生用于绘图的差值均值、上下一致性界限、0值参考线*/
proc means mean std noprint;
var dif;
output out=st mean= dmean std=std;
run;
data st(drop=_type_ _freq_);
set st;
uclm=dmean+1.96*std;
lclm=dmean-1.96*std;
zero=0;
run;
/*步骤2：将含各指标的数据集与原始数据集合并，用于下一步的制图*/
proc sql;
create table ba as
select * from example9_8,st;
quit;
proc sort data=ba;
by mean;
run;
/*步骤3：利用proc sgplot过程制图，利用series语句绘制4条线，并分别设定其相应属性*/
proc sgplot data=ba;
scatter x=mean y=dif ;
series x=mean y=uclm/curvelabel="+1.96标准差" curvelabelloc= outside lineattrs=(pattern=4);
series x=mean y=dmean/curvelabel="差值均值" curvelabelloc= outside lineattrs=(pattern=1);
series x=mean y=lclm/curvelabel="-1.96标准差" curvelabelloc= outside lineattrs=(pattern=4);
series x=mean y=zero/curvelabel="0值参考线" curvelabelloc= outside lineattrs=(pattern=2) ;
yaxis values=(-4 to 4);
run;
