通过 SQL 计算一列中的值 - 使用 SAS [英] count the values in one column by SQL - using SAS
本文介绍了通过 SQL 计算一列中的值 - 使用 SAS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 customer_no
和 class
.我想从每个客户的同一列计算比率.
I have a customer_no
and class
.
I would like to calculate ratio from the same column for each customer.
ratio= (number of secured/ total number classes)
customer_no class
1 unsecured
1 secured
1 secured
2 unsecured
2 secured
3 secured
3 unsecured
3 secured
3 unsecured
输出样本将是
customer_no ratio
1 0.666
2 0.50
3 0.50
.
.
.
20000
推荐答案
proc sql;
create table want as
select customer_no
,sum(case when class='secured' then 1 else 0 end)/count(customer_no) as ratio
from WORK.ENQUIRY_30
group by customer_no;
quit;
这篇关于通过 SQL 计算一列中的值 - 使用 SAS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文