标题: 再来一个HOMEWORK:表格相减 [打印本页] 作者: shiyiming 时间: 2004-6-9 04:57 标题: 再来一个HOMEWORK:表格相减 有2个表格A,B,要求从A中删除B中有的记录,且维持原表顺序,例如表A
data a;
input id value;
cards;
1 1
2 3
3 1
4 4
5 5
6 2
7 1
8 4
9 3
10 1
;
run;
表B
data b;
input value;
cards;
2
4
;
run;
结果应该是
id value
1 1
2 3
3 1
5 5
7 1
9 3
10 1
我作了一个,可总觉得效率不高,表的遍历过多,表格大的话就很慢了
data temp;
set a b(in=bb);
if (bb=1) then id=0;
run;
proc sort data=temp;
by value id;
run;
data res (drop=cur);
set temp;
retain cur -1;
if id=0 then
cur=value;
else do;
if (value ne cur) then output;
end;
run;
proc sort data=res;
by id;
run;作者: shiyiming 时间: 2004-6-9 08:56 标题: ANSWER 试试这个:
[code:f87c9]PROC SQL;
SELECT * FROM A
WHERE VALUE NOT IN (SELECT VALUE FROM B);
QUIT;[/code:f87c9]作者: shiyiming 时间: 2004-6-9 09:00 标题: ANSWER2 再试试这个:
[code:b4360]PROC SQL NOPRINT;
SELECT DISTINCT VALUE INTO :STRVALUE SEPARATED BY ',' FROM B;
QUIT;
DATA RESULT;
SET A;
WHERE VALUE NOT IN (&STRVALUE);
RUN;[/code:b4360]作者: shiyiming 时间: 2004-6-9 10:11 标题: Try this! [code:3436b]proc sort data=a;
by value;
run;
data tmp;
merge a b(in=d);
by value;
if not d;
run;