如果较小的表中的行的主键值不在较大的表中,我试图将一个较小的表中的记录添加到一个非常大的表中:
data test;
Length B C $4;
infile datalines delimiter=',';
input a b $ c $;
datalines;
1000,Test,File
2000,Test,File
3000,Test,File
;
data test2;
Length B C $4;
infile datalines delimiter=',';
input a b $ c $;
datalines;
1000,Test,File
4000,Test,File
;
proc sql;
insert into test
select * from test2
where a not in (select a from test2);
quit;
然而,这使得表Test
中没有记录。谁能告诉我我做错了什么?最终结果应该是a = 4000的行应该添加到表Test
。
编辑:
使用where a not in (select a from test)
是我最初尝试过的,它产生了以下错误:
WARNING: This DELETE/INSERT statement recursively references the target table. A consequence of this is a possible data integrity problem.
ERROR: You cannot reopen WORK.TEST.DATA for update access with member-level control because WORK.TEST.DATA is in use by you in resource
environment SQL.
ERROR: PROC SQL could not undo this statement if an ERROR were to happen as it could not obtain exclusive access to the data set. This
statement will not execute as the SQL option UNDO_POLICY=REQUIRED is in effect.
224 quit;
由于
答案 0 :(得分:6)
您可以分两步完成此过程。首先创建要插入的记录表,然后插入它们。
proc sql undo_policy=none;
insert into test
select * from test2
where a not in (select a from test)
;
quit;
或者您可以只更改UNDO_POLICY选项的设置,SAS会让您在更新TEST时参考TEST。
Cannot connect to https://*.atlassian.net Request failed. Reason: "Field 'summary' does not exist or this field cannot be viewed by anonymous users." "Field 'assignee' does not exist or this field cannot be viewed by anonymous users." "Field 'resolution' does not exist or this field cannot be viewed by anonymous users."