-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