jihezi927 发表于 2013-5-24 00:39 
以上是方法都是要create一个新的table,有什么办法只更新旧table中的数据
LZ的想法是对的。 当原来的表很大时,再 create 一个新表显然是不合适的, 尤其是是当原来的表连接着其他表时。 正确的方法是用一个小的新表里的数据来更新 (update)大表中的数据。
sas 有两种更新表格的方法, 楼上已经提到了.
一种方法是用 proc sql; update table statement (沙发, 7楼, 12楼)。
proc sql;
update oldtable as old
set column_to_be_updated=(select column_to_be_updated
from newtable as new
where condition ) /* such as: where old.var1 = new.ver2) */
where other_condition;
quit;
另一种方法是用 data step the modify statement(15楼).
另外还可一用 data step 的 update 语句。 如果用14 楼排过续的数据集。code 写为
data prd_price;
update prd_price sale_new;
by id;
run;
这里说的更新(update), 是指只改变原表中的数据, 而不改变原表的结构与变量的特性。
而其他的方法, 如 data step merge, proc sql; left/right join 虽然也可以用一个表的数据来替换另一个表中的数据。 但这些方法的主要目的是从多个表中找出相匹配的数据,从而形成新表或者报告。
而且新表的结构会与原表不同, 比如,加入新的变量。
如果你的数据不多, 而且与其他表格没有关系。 当然用merge 和proc sql; left/right join 方便些. 至少可以保留一份原始数据.
update 在数据库中用的比较多.