2012-04-16 84 views
0

是否有人知道如何在SAS PROC SQL中将“新”行插入到现有表中?如何只插入新的(不重复)行到现有的表 - 在proc sql -sas?

proc sql; 
create table class as 
select * 
from sashelp.class 
where sex = 'F'; 
quit; 

proc sql; 
create table classm as 
select * 
from sashelp.class 
where sex = 'M' or Name = 'Alice'; 
quit; 

proc sql; 
insert into class 
select * 
from classm ; 
quit; 

insert语句不允许我使用WHERE语句插入来自classm只有10个新行(无爱丽丝)

有什么办法去解决这个?因为我正在处理大数据,所以我想在proc sql中执行此操作,或者数据步骤正常。

感谢

+2

将主键添加到表定义是强制表拒绝重复项的另一种方法。请参阅:http://support.sas.com/documentation/cdl/en/sqlproc/62086/HTML/default/viewer.htm#a001396785.htm – DataParadigms 2012-04-16 16:54:24

+0

我不太了解您的情况。但似乎构建一个复杂的where子句,如where(sex ='M'或Name ='Alice')或sex ='F''可能是解决方案。 – 2012-04-17 04:41:53

回答

2

这个工作对我来说...

proc sql; 
create table class as 
select * 
from sashelp.class 
where sex = 'F'; 
quit; 

proc sql; 
create table classm as 
select * 
from sashelp.class 
where sex = 'M' or Name = 'Alice'; 
quit; 

proc sql; 
insert into class 
select * 
from classm 
where name^="John"; 
quit; 
+0

这也适用于我。 – DataParadigms 2012-04-16 16:55:53

0

为什么不使用合并?

您按照引用(id)的列对两个表进行排序,并将两个表与所选键合并。