加入时删除 table
Delete table on join
在 T-SQL 中,我曾经能够做到以下几点:
delete t1
from table1 t1
join table2 t2 on t1.rowid = t2.rowid and t1.value <> t2.value
我希望能够在 SAS 中做同样的事情。
采用上面的代码并包装在 proc sql 中;并退出;抛出语法错误。
下面是我唯一的选择吗?
proc sql;
delete from table1 t1
where t1.value <> (select t2.value from table2 t2 where t1.rowid = t2.rowid)
and t1.rowid in (select t2.rowid from table t2);
quit;
谢谢。
所以你可能已经发现,删除不是很有效。
如果您有磁盘 space,我建议只根据内部连接(您想要的记录)创建一个新的 table,删除 table1,然后重命名结果 table1.
%let n=1000000;
data table1;
do rowid=1 to &n;
value = rowid**2;
output;
end;
run;
data table2;
do rowid=1 to &n;
value = (mod(rowid,2)=1)*rowid**2;
output;
end;
run;
proc sql noprint;
create table table1_new as
select a.*
from table1 as a
inner join
table2 as b
on a.rowid=b.rowid
and
a.value = b.value;
drop table table1;
quit;
proc datasets lib=work nolist;
change table1_new = table1;
run;
quit;
在 T-SQL 中,我曾经能够做到以下几点:
delete t1
from table1 t1
join table2 t2 on t1.rowid = t2.rowid and t1.value <> t2.value
我希望能够在 SAS 中做同样的事情。
采用上面的代码并包装在 proc sql 中;并退出;抛出语法错误。
下面是我唯一的选择吗?
proc sql;
delete from table1 t1
where t1.value <> (select t2.value from table2 t2 where t1.rowid = t2.rowid)
and t1.rowid in (select t2.rowid from table t2);
quit;
谢谢。
所以你可能已经发现,删除不是很有效。
如果您有磁盘 space,我建议只根据内部连接(您想要的记录)创建一个新的 table,删除 table1,然后重命名结果 table1.
%let n=1000000;
data table1;
do rowid=1 to &n;
value = rowid**2;
output;
end;
run;
data table2;
do rowid=1 to &n;
value = (mod(rowid,2)=1)*rowid**2;
output;
end;
run;
proc sql noprint;
create table table1_new as
select a.*
from table1 as a
inner join
table2 as b
on a.rowid=b.rowid
and
a.value = b.value;
drop table table1;
quit;
proc datasets lib=work nolist;
change table1_new = table1;
run;
quit;