全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
6214 11
2010-05-01
有一个数据是这样的,每个entry是顾客的fund account,种类有equity, bonds 和 others



customer     fund category            balances
1                         equity                        100
1                         equity                        200
1                         bonds                         120
2                        bonds                           300
2                         others                        210
3                         bonds                          100


现在我需要把这样的一个数据合并成一个以每个顾客编号为准的文件,里面包括每个fund的数量和总的fund数量
也就是

customer      N_equity        N_bonds    N_others        N_total        total_balance
1                      2                      1                 0                      3
2                      0                        1                1                     2  
3                      0                     1                   0                       1


请教大牛,如何让sas这样count 出这些categorical variable的个数呢?
多谢
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2010-5-1 12:14:16
data a;
input customer fund$ balances@;
cards;
1   equity  100
1   equity   200
1   bonds    120
2    bonds  300
2    others 210
3    bonds     100
;
run;
proc sql;
create table b as select customer,fund, count(fund) as count,sum(balances) as  total from a group by customer,fund;
create table b as select customer,fund ,count,sum(total) as total_balances from b group by customer;
quit;
proc transpose data=b out=c prefix=N_;
id fund;
var count;
by customer total_balances;
run;
data d;
set c;
drop _name_;
N_total=sum(N_bonds,N_others,N_equity);
run;

方法很笨
但是可以解决问题
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-5-1 12:17:36
crackman 发表于 2010-5-1 12:14
data a;
input customer fund$ balances@;
cards;
1   equity  100
1   equity   200
1   bonds    120
2    bonds  300
2    others 210
3    bonds     100
;
run;
proc sql;
create table b as select customer,fund, count(fund) as count,sum(balances) as  total from a group by customer,fund;
create table b as select customer,fund ,count,sum(total) as total_balances from b group by customer;
quit;
proc transpose data=b out=c prefix=N_;
id fund;
var count;
by customer total_balances;
run;
data d;
set c;
drop _name_;
N_total=n(N_bonds,N_others,N_equity);
run;

方法很笨
但是可以解决问题
N_total=n(N_bonds,N_others,N_equity); 这里n是个数,应该是 sum吧?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-5-1 12:21:22
就是就是
怎么我一出来就看到你呢
哥们
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-5-1 12:32:18
crackman 发表于 2010-5-1 12:21
就是就是
怎么我一出来就看到你呢
哥们
你抢了我的transpose不找你找谁?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-5-1 12:46:45
不好意思
你还一个方法
做出来了我给你100论坛币
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群