Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用此SQL摘要函数_Sql_Sas - Fatal编程技术网

无法使用此SQL摘要函数

无法使用此SQL摘要函数,sql,sas,Sql,Sas,在SAS SQL中生成摘要值的这一练习整天都让我疲惫不堪。它的SAS部分基本上只是我模拟一些数据,如果您想尝试回答问题,一般SQL原则适用 考虑以下因素: 输入数据 data test; account_rk = 111111; customer_rk = 111111; ca_flag = 0; score1 = 100; score_with_ca = 0; score_without_ca = 100; output; account_rk = 111111; customer_rk =

在SAS SQL中生成摘要值的这一练习整天都让我疲惫不堪。它的SAS部分基本上只是我模拟一些数据,如果您想尝试回答问题,一般SQL原则适用

考虑以下因素:

输入数据

data test;
account_rk = 111111;
customer_rk = 111111;
ca_flag = 0;
score1 = 100;
score_with_ca = 0;
score_without_ca = 100;
output;
account_rk = 111111;
customer_rk = 222222;
ca_flag = 1;
score1 = 150;
score_with_ca = 150;
score_without_ca = 0;
output;
run;
已尝试摘要功能

proc sql;
create table test2 as 
select
account_rk,
sum(ca_flag) as sum_ca_flag,
    min(case
    when score_with_ca ne 0 then score_with_ca
    else score1 end) as min_score_with_ca,
    min(case 
    when score_without_ca eq 0 then score_without_ca
    else score1 end) as min_score_without_ca
from test
group by account_rk
having sum_ca_flag > 0;
quit;
期望的结果应该是什么样的

data test3;
account_rk = 111111;
sum_ca_flag = 1;
min_score_with_ca = 150;
min_score_without_ca = 100;
output;
run;
为了得到与第三步中生成的输出类似的输出,我需要在SQL中更改什么?这里的逻辑步骤是根据
ca\u flag
的值为
score1
生成最小值,并按
account\u rk
对其进行分组

谁能告诉我我做错了什么


谢谢

我想您只需要
NULL
或no
else
子句,然后是正确的逻辑:

proc sql;
create table test2 as 
    select account_rk, sum(ca_flag) as sum_ca_flag,
           min(case when score_with_ca > 0 then score_with_ca
               end) as min_score_with_ca,
           min(case when score_without_ca > 0 then score_without_ca
               end) as min_score_without_ca
    from test
    group by account_rk
    having sum_ca_flag > 0;
quit;

当你有Ca标志时,用Ca检查分数或不用Ca检查分数似乎很奇怪;但我认为这不是问题所在。谢谢你的回复。我想我这一天过得很糟糕…这是一个很容易解决的问题。。。