本站分享:AI、大数据、数据分析师培训认证考试,包括:Python培训Excel培训Matlab培训SPSS培训SAS培训R语言培训Hadoop培训Amos培训Stata培训Eviews培训

sas 分类求和_sas 分类占比相关问题解析

sas培训 cdadata 4571℃

sas 分类求和_sas 分类占比相关问题解析

关键词:sas 分类求和,sas 分类占比,sas 求和

请高手帮忙, 现有一个数据集需要统计。内容是每个销售人员对不同客户的销售次数,金额,对每个客户可以有2种类型的销售行为,其中只有第一类有金额产生,第二类不产生金额。如图test2. 客户中有一部分是北京的,其余不是。

现在希望得到的2个数据集

第一个:

按每个销售人员进行统计。 第一列销售人员代码,第二列北京的客户数,第三列销售次数总计(北京客户),第四列金额总计(北京客户),第五列北京客户数占总客户数的%,第六列北京客户销售次数占总次数的%,第七列北京客户金额占总销售金额的%;

第二个:

按每个销售人员对应的客户进行统计。 第一列销售人员代码,第二列客户代码,第三列销售次数总计,第四列金额总计,第五列销售额占这个销售人员总销售额的%,第六列金额总计在这个销售人员总销售金额的%;

请问该怎么写代码才能得到我要的数据集呢?关联北京客户部分没问题。主要是关联好了之后如何进一步处理。
原始数据
sales,client,type,times,amount
jame,a001,1,10,45
jame,a001,0,3,.
jame,a002,1,11,67
jame,a002,0,9,.
jame,a003,1,33,99
jame,a003,0,10,.
jame,a004,0,34,.
david,a002,1,11,22
david,a002,0,23,.
david,b001,1,12,27
david,b001,0,16,.
david,b002,1,13,38
david,b002,0,9,.
david,b004,1,14,38
david,b004,0,43,.
david,c001,1,15,38
micheal,a001,1,25,26
micheal,a001,0,16,.
micheal,a002,1,16,49
micheal,a002,0,17,.
micheal,b003,1,18,77
micheal,b003,0,19,.
micheal,d001,1,16,58
micheal,d001,0,21,.
micheal,e001,0,22,.
jacky,f011,1,26,56
jacky,f011,0,21,.
jacky,d009,1,13,59
jacky,d009,0,16,.
jacky,d008,1,17,94
jacky,d008,0,17,.
jacky,w011,1,17,83
jacky,w011,0,33,.
jacky,q001,1,32,59
jacky,q001,0,25,.
jacky,a002,1,27,126
jacky,a002,0,37,.
jacky,c012,1,18,117
jacky,c012,0,9,.
jacky,b003,1,42,231
jacky,b003,0,33,.

北京客户数据
client city
a001 1
a002 1
a003 1
a004 1
b004 1
b003 1
b002 1
b001 1
c001 1
e001 1
f011 1
w011 1
d009 1
d008 1

test2_1.jpg (21.14 KB, 下载次数: 0)

sas 分类求和_sas 分类占比相关问题解析

test2.jpg (81.23 KB, 下载次数: 0)

sas 分类求和_sas 分类占比相关问题解析


数据集sale_city与13楼的相同。运行下面的code可得到你要的结果。

proc sql;
create table table1 as
select  a.sales as sales,
a.NB_Client as nb,
a.NB_client / b.N_Client  as  nb_pct format=percent7.2,
a.TB_sale_time as freq,
a.TB_sale_time / b.sum_time as freq_pct format=percent7.2,
a.TB_amount as amount,
a.TB_amount / b.sum_amount as amount_pct format=percent7.2
from (select sales,
count(distinct client) as NB_client,
sum(times) as TB_sale_time,
sum(amount) as TB_amount
from sale_city
where city = 1
group by sales) as a,
(select sales, count(distinct client) as N_client,
sum(times) as sum_time,
sum(amount) as sum_amount
from sale_city
group by sales) as b
where a.sales = b.sales;
quit;
proc sql;
create table table20 as;
select *,  sum(times) as sum_time, sum(amount) as sum_amount
from sale_city
where city=1
group by sales;
create table table2 as
select sales, client,
sum(times)    as time,
sum(amount) as amount,
sum(times)/sum_time    as time_pct   format=percent7.2,
sum(amount)/sum_amount as amount_pct   format=percent7.2
from table20
group by sales, client
order by sales, client;
* drop table table20;
quit;
proc sort data = table2 out=table2_final nodup; by sales client; run;

proc print data=table1; run;
proc print data=table2_final; title ‘table2_final’; run;

转载请注明:数据分析 » sas 分类求和_sas 分类占比相关问题解析

喜欢 (1)or分享 (0)