我想知道是否有可能由于单个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