-1
我试图运行下面的代码,但它无法正常工作。我发现问题是每个case when
都会覆盖下一条语句。使用PROC SQL作为IF/ELSE IF语句
所以,我需要做的是一个IF/ELSE IF
staetment,但我不知道该怎么做,在PROC-SQL
proc sql;
create table example
as select *,
case when B.variable = 'X' then 1 else 0 end as variable_X,
case when B.variable = 'Y' then 1 else 0 end as variable_Y,
case when B.variable = 'Z' then 1 else 0 end as variable_Z,
case when B.variable = 'W' then 1 else 0 end as variable_W,
case when B.variable = 'R' then 1 else 0 end as variable_R,
case when B.variable = 'G' then 1 else 0 end as variable_G,
case when B.variable = 'T' then 1 else 0 end as variable_T,
case when B.variable = 'U' then 1 else 0 end as variable_U,
case when B.variable = 'P' then 1 else 0 end as variable_P,
case when B.variable = 'L' then 1 else 0 end as variable_L
FROM my_table as A
LEFT JOIN my_second_table as B
on A.KEY1=E.KEY1 and A.KEY2=E.KEY2
;
我已经尝试过使用group by
声明,但它没”工作。
P.S .:我真实的代码比我的例子大得多,有8 left join
以及更多的变量。我刚刚发布了它的摘录。
您对“覆盖”的评论没有意义。你当然可以做(或多或少)你在做什么,并得到一个潜在的有效结果。 – Joe