比较列值

时间:2016-12-05 19:08:10

标签: sas

我有5列,想要检查哪些列具有确切的值

num1 num2 num3 num4 num5
1     2    2    3    1
2     3    3    2    2
2     2    2    2    2
4     5    6    7    4

此处列1(num1)和last(num5)在任何地方都具有完全相同的值。我怎么能找到它?

1 个答案:

答案 0 :(得分:1)

您可以转置然后查找重复的行。

data have ;
 input num1-num5 ;
cards;
1  2  2  3  1
2  3  3  2  2
2  2  2  2  2
4  5  6  7  4
;
data _null_;
 call symputx('nobs',nobs);
 stop;
 set have nobs=nobs;
run;
proc transpose data=have out=tran; var num1-num5; run;
proc sort data=tran; by col1-col&nobs; run;
data want;
 set tran ;
 by col1-col&nobs;
 if not (first.col&nobs and last.col&nobs) ;
run;
proc print data=want;
run;

结果

Obs    _NAME_    COL1    COL2    COL3    COL4
 1      num1       1       2       2       4
 2      num5       1       2       2       4