我想知道是否有可能由於單個CASE而執行多個分配。也就是說,不是有兩個CASE語句,而是有一個CASE語句,它有一個'then-do-end'結構。SAS:PROC SQL作爲單個CASE的結果的多個分配
例如,如何根據單個CASE語句中的x
將值分配給thing1
和thing2
?
data example;
input x $;
datalines;
A
A
A
B
B
;
run;
proc sql;
create table make_two_from_one as
select *
, case
when x = 'A' then 'Result1A'
when x = 'B' then 'Result1B'
else 'Error'
end as thing1
, case
when x = 'A' then 'Result2A'
when x = 'B' then 'Result2B'
else 'Error'
end as thing2
from example
;
quit;
不幸的是,這不是SQL的工作原理。 –
你可以在組中添加計數嗎?然後選擇價值和它的計數的組合? (對於第一部分,請看這裏:http://stackoverflow.com/questions/17006765/get-a-the-row-number-in-a-data-step-using-sas) – johnjps111
或者你可以這樣做一個數據步驟,因爲SQL沒有任何數據步驟難以複製的東西。 – Reeza