使用 proc sql 更新
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24629793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
update with a proc sql
提问by Andy K
It should be an easy one but I'm stuck
这应该很容易,但我被卡住了
Proc sql;
UPDATE dicofr
SET dicofr.period = correspondance.period
FROM dicofr
INNER JOIN correspondance
ON dicofr.name_fic = correspondance.name_fic;
I was thinking my update would be done but I got this error instead.
我以为我的更新会完成,但我收到了这个错误。
271 proc sql;
272 update dicofr
273 set dicofr.period = correspondance.period
-
73
76
ERROR 73-322: Expecting an =.
ERROR 76-322: Syntax error, statement will be ignored.
I've tried with a straight join with a select
我试过直接连接 select
proc sql;
SELECT * FROM dicofr INNER JOIN correspondance
ON dicofr.nom_fic=correspondance.nom_fic;
The select is fine.
选择没问题。
How come?
怎么来的?
Is my SQL query not correct? I don't think so ...
我的 SQL 查询不正确吗?我不这么认为...
Edited: It seems the update I want to do is not possible. Is there a way to do what I want with SAS language?
编辑:看来我想做的更新是不可能的。有没有办法用 SAS 语言做我想做的事?
回答by Joe
SAS doesn't support JOINs in an UPDATE statement, for some reason. You need to do it through a nested select.
出于某种原因,SAS 不支持 UPDATE 语句中的 JOIN。您需要通过嵌套选择来完成。
proc sql;
update tableA A
set var=
(select var
from tableB B
where B.id=A.id)
where exists (
select 1
from tableB B
where B.id=A.id);
quit;
回答by Ankit Bajpai
Yer you are taking a wrong approach. Try somthing like this:-
你采取了错误的方法。尝试这样的事情:-
UPDATE dicofr INNER JOIN correspondance
ON dicofr.name_fic = correspondance.name_fic;
SET dicofr.period = correspondance.period
WHERE cond....