英文:
In SAS EG4 i have to find Top 10 customer name within top 10 country name by region
问题
以下是示例数据:
Data read;
input region$ Country$ Customername$ Amount;
dataline;
asia china xx 78
asia pak xx 89
africa tunisia xx
contd
;
run;
我想要每个地区前10个国家的前10位客户。有人可以指导或帮助吗?
我尝试了Proc tabulate和proc means,但没有得到结果。我无法在办公电脑上显示结果。
英文:
below is the sample data
Data read;
input region$ Country$ Customername$ Amount;
dataline;
asia china xx 78
asia pak xx 89
africa tunisia xx
contd
;
run;
I want top 10 customer of top 10 country by region. Can anyone guide or help
i tried Proc tabulate and proc means but not giving results. I cannot show the result as it is office laptop
答案1
得分: 0
You didn't show the Proc MEANS
code you tried.
Try using Proc MEANS with some follow-up SORT and DATA steps to get the results you want.
示例:
data have;
call streaminit(20230417);
do region = 1 to 20;
do customer = 1 to 100+rand('integer', 25);
customerId + 1;
amount = rand('integer', 1, 2500);
output;
end;
end;
keep region customerid amount;
run;
proc means noprint data=have;
class region customerId;
var amount;
types region region*customerId;
output out=summary sum=totalamount;
run;
proc sort data=summary;
by region descending totalamount;
data top10region;
set summary;
where _type_ = 2;
if _n_ > 10 then stop;
run;
data top10c_in_top10r;
merge top10region(rename=totalamount=regiontotal) summary(where=(_type_=3));
by region;
if first.region then regionCount + 1;
if regionCount > 10 then stop;
if first.region
then counter = 1;
else counter + 1;
if counter <= 10 then output;
keep region customerId regionTotal regionTotal totalAmount;
rename totalAmount=customerTotal;
run;
英文:
You didn't show the Proc MEANS
code you tried.
Try using Proc MEANS with some follow up SORT and DATA steps to get the results you want.
Example:
data have;
call streaminit(20230417);
do region = 1 to 20;
do customer = 1 to 100+rand('integer', 25);
customerId + 1;
amount = rand('integer', 1, 2500);
output;
end;
end;
keep region customerid amount;
run;
proc means noprint data=have;
class region customerId;
var amount;
types region region*customerId;
output out=summary sum=totalamount;
run;
proc sort data=summary;
by region descending totalamount;
data top10region;
set summary;
where _type_ = 2;
if _n_ > 10 then stop;
run;
data top10c_in_top10r;
merge top10region(rename=totalamount=regiontotal) summary(where=(_type_=3));
by region;
if first.region then regionCount + 1;
if regionCount > 10 then stop;
if first.region
then counter = 1;
else counter + 1;
if counter <= 10 then output;
keep region customerId regionTotal regionTotal totalAmount;
rename totalAmount=customerTotal;
run;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论