y***e 发帖数: 6 | 1 今天碰到个问题
想请问较快的解决办法
data如下
ID A1 A2 A3 A4
1 0 7 8 .
2 6 8 1 0
3 . . . .
4 9 7 4 0
5 0 . . .
**我想要的subject: 只要有一个值不是missing就留下 全是missing的subject就删除**
所以除了subject 3 以外 全都留著
目前想到的办法是算sum (sum不是missing就代表起码有一个值)
另一个是找maximum (maximum不是missing就一定有个值)
想问问可不可以用array的写法把subject挑出来呢?
还是新手 请多指教 |
R*********i 发帖数: 7643 | |
h********o 发帖数: 103 | 3 Using SUM or MAX functions is a good and simple way to solve your problem.
Why do you need complicate way by using ARRAY?
=====================
IF MISSING(MAX(OF A1-A4)) THEN DELETE;
IF MISSING(SUM(OF A1-A4)) THEN DELETE; |
t****g 发帖数: 35 | 4 一定要用的话,可以这样吗?
input id x1 x2 x3 x4;
cards;
1 3 2 5 3
2 3 3 . .
3 . . . .
4 3 . . .
5 2 3 6 3
;
run;
data b(drop=i);
set a;
array missck(4) x1-x4;
do i =1 to 4;
if missck(i) ne '.' then output;
end;
run;
proc sort data=b;
by id;
run;
data c;
set b;
by id;
if first.id;
run; |
j******o 发帖数: 127 | 5 Try this.
data have;
input id x1 x2 x3 x4;
datalines;
1 0 7 8 .
2 6 8 1 0
3 . . . .
4 9 7 4 0
5 0 . . .
;
run;
data obtain;
set have;
array a{4} x1-x4;
t=0;
do i=1 to 4;
if not missing(a{i}) then t+1;
end;
if t ne 0;
drop t i;
run; |
j******o 发帖数: 127 | 6 Yes, I agree. For this case, SUM or MAX is workable. However, I am more
likely to vote array since it is more efficient and expandable for
additional complicated conditions.
problem.
【在 h********o 的大作中提到】 : Using SUM or MAX functions is a good and simple way to solve your problem. : Why do you need complicate way by using ARRAY? : ===================== : IF MISSING(MAX(OF A1-A4)) THEN DELETE; : IF MISSING(SUM(OF A1-A4)) THEN DELETE;
|