|
没弄明白第二个表第六列是什么意思,可能不是LZ想要的.
是不是这样
data testsale;
infile datalines dlm=',';
input sales $ client $ type times amount;
datalines;
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,.
; run;
data city;
input client $ city;
datalines;
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
;
proc sql;
create table sale_city as
select *
from testsale a left join city b
on a.client=b.client;
quit;
proc sql;
create table table1 as
select sales,
count(distinct client) as NB_Client,
sum(times) as TB_sale_time,
sum(amount) as TB_amount,
(calculated NB_Client )/(select count(distinct Client) from sale_city)
as Percent_B_Client format=percent6.2,
(calculated TB_sale_time)/(select sum(times) from sale_city where type=1)
as Percent_B_sale_time format=percent6.2,
(calculated TB_amount)/ (select sum(amount) from sale_city where type=1)
as Percent_B_amount format=percent6.2
from sale_city
where type=1 and city=1
group by sales;
quit;
proc sql;
create table table20 as
select *, sum(amount) as TS_amount
from sale_city
group by sales
having type = 1;
create table table2 as
select sales, client,
sum(times) as TSC_time,
sum(amount) as TSC_amount,
sum(amount) / TS_amount as Percent_SC format=percent6.2,
sum(amount) / (select sum(amount) from table20)
as Percent_T_amount format=percent6.2
from table20
group by sales, client;
drop table table20;
quit;
proc print data=table1; title 'table1'; run;
proc print data=table2; title 'table2'; run;
|