先贴一个比较笨的办法,就是要把所有的项目都得输入一遍,
proc sql;
select Name, count(unique a) as NumA, count(unique b) as NumB, count(unique c) as NumC, count(unique d) as NumD
from a
group by name
having NumA>1 or NumB>1 or NumC>1 or NumD>1;
quit;
[code:3stqdlby]
/*思路1:取出每个运动员每个项目的最高得分和最低得分,如果最高分=最低分,即:极差=0,那么所有裁判的打分相同,否则,至少有一个裁判的打分与其他不一样*/
proc means data=a nway noprint;
var a c b d;
class name;
output out=aa(drop=_type_ _freq_) range(a b c d)=r_a r_b r_c r_d;
run;
data result(drop=r_a--r_d) ;
set aa;
if r_a then a='N';
else a='Y';
if r_b then b='N';
else b='Y';
if r_c then c='N';
else c='Y';
if r_d then d='N';
else d='Y';
run;
/*思路2:就是搂主的叙述*/
proc sort data=a out=aa noduprecs noequals;
by name;
run;
data result(rename=(r_a=a r_b=b r_c=c r_d=d));
set aa;
by name;
retain tmp_a tmp_b tmp_c tmp_d;
retain r_a r_b r_c r_d;
if first.name then do;
tmp_a=a;tmp_b=b;tmp_c=c;tmp_d=d;
r_a='Y';r_b='Y';r_c='Y';r_d='Y';
end;
if a^=tmp_a then r_a='N';
if b^=tmp_b then r_b='N';
if c^=tmp_c then r_c='N';
if d^=tmp_d then r_d='N';
if last.name;
drop a--d tmp_a--tmp_d;
run;
[code:31ounr0f]data aa;
input name $ a b c d ;
cards;
XX 1 2 3 4
XX 1 2 3 4
XX 2 2 3 4
YY 1 1 1 1
YY 1 1 1 2
ZZZ 3 3 3 3
ZZZ 3 3 3 3
ZZZ 3 3 3 3
ZZZ 3 3 3 3
;
proc sort;by name;run;
proc sql noprint;
select count(name) into :n from sashelp.vcolumn
where libname='WORK' and memname='AA' and type='num';
select name into :name separated by ' ' from sashelp.vcolumn
where libname='WORK' and memname='AA' and type='num';
quit;
data bb(drop=&name i x);
set aa;by name;
array aa _numeric_;
array bb(&n);
do i=1 to dim(aa);
x=lag(aa(i));
if aa(i)-x=0 then aa(i)=.;
if first.name then aa(i)=.;
bb(i)=aa(i);
end;
run;
data cc(keep=name &name);
set bb;by name;
array aa _numeric_;
array bb(&n) $ &name;
do i=1 to &n;
y=lag(aa(i));
aa(i)=sum(y,aa(i));
if aa(i) ne . then bb(i)='N';
end;
if last.name;
run;
[/code:31ounr0f]
笨办法之完整版,中间的if条件比较罗嗦,也许可以做循环。不过我还没有实现:
data a;
input name $ a b c d;
cards;
XX 1 2 3 4
XX 1 2 3 4
XX 2 2 3 4
YY 1 1 1 1
YY 1 1 1 2
ZZ 3 3 3 3
ZZ 3 3 3 3
ZZ 3 3 3 3
ZZ 3 3 3 3
;
run;
proc sql;
create table b as
select Name, count(unique a) as A, count(unique b) as B, count(unique c) as C, count(unique d) as D
from a
group by name;
quit;
data c;
set b;
length sa sb sc sd total $20.;
if A>1 then sa='A';
if B>1 then sb='B';
if C>1 then sc='C';
if D>1 then sd='D';
total=trim(left(trim(left(sa))||trim(left(sb))||trim(left(sc))||trim(left(sd))));
keep name total;
run;