我需要创建一个数据集(TABLE3),以检查其他两个表中的某些变量是否相等。如果是这样,代码必须返回0,否则返回1.但是,因为我是SAS和SQL的新用户,我正在努力弄清楚如何做到这一点。
我正在尝试这样的事情,但它不起作用。
PROC SQL;
CREATE TABLE TABLE3 AS
SELECT A.*, B.*
CASE WHEN B.VARIABLE1 = A.VARIABLE2 THEN 0 ELSE 1 END AS VARIABLE_1_2,
CASE WHEN B.VARIABLE3 = A.VARIABLE4 THEN 0 ELSE 1 END AS VARIABLE_3_4
FROM TABLE1 AS A
LEFT JOIN TABLE2 AS B;
P.S。:变量1,2,3和4都是字符变量。
答案 0 :(得分:0)
要使JOIN条件起作用,必须有一个ON子句
PROC SQL;
CREATE TABLE TABLE3 AS
SELECT A.*, B.*,
CASE WHEN B.VARIABLE1 = A.VARIABLE2 THEN 0 ELSE 1 END AS VARIABLE_1_2,
CASE WHEN B.VARIABLE3 = A.VARIABLE4 THEN 0 ELSE 1 END AS VARIABLE_3_4
FROM TABLE1 AS A LEFT JOIN TABLE2 AS B
**ON TABLE1.SOME_COLUMN_NAME = TABLE2.SOME_COLUMN_NAME**
;
答案 1 :(得分:0)
除了表关系之外,你必须在加入后添加,你会错过昏迷","就在第一个案例之前。