我有两列,想创建第三列。我想要创造的逻辑是; A列代表唯一的客户记录。对于基于A栏中的电子邮件或ID号的每个唯一客户,我想查看B列,如果有POS和Web混合,则第三列= MC,如果不是,那么非MC。
Column A Column B Column C
test@test.com POS MC
test@test.com POS MC
test@test.com WEB MC
test123@test.com POS not MC
123456 POS MC
123456 WEB MC
123458 WEB not MC
答案 0 :(得分:1)
您可以在PROC SQL
:
proc sql ; create table want as select h1.A, h1.B, h2.UNIQUE_B, case when h2.UNIQUE_B = 1 then 'Not MC' else 'MC' end as MC from have h1 left join (select A, count(distinct(B)) as UNIQUE_B from have group by A) h2 on h1.A = h2.A order by h1.A ; quit ;
答案 1 :(得分:0)
好的,所以我理解,A列是" ID"和B列是"频道"在我的数据集中,我已经相应地更改了代码,但是日志在模糊不清中引发了一些错误,所以我想我在这里错过了你的引用。代码看起来是否正确?
proc sql ;
create table Aimee.MCreport as
select ID, Channel, Channel.UNIQUE_Channel, case when Channel.UNIQUE_Channel = 1 then 'Not MC' else 'MC' end as MC
from Aimee.Weekly_Email_files_cleaned3 ID
left join
(select ID, count(distinct(Channel)) as UNIQUE_Channel
from Aimee.Weekly_Email_files_cleaned3
group by ID) Channel on ID = Channel
order by ID ;
quit ;