在SAS EG4中,我需要找到按地区排名的前10个国家名称内的前10个客户名称。

huangapple go评论97阅读模式
英文:

In SAS EG4 i have to find Top 10 customer name within top 10 country name by region

问题

以下是示例数据:

  1. Data read;
  2. input region$ Country$ Customername$ Amount;
  3. dataline;
  4. asia china xx 78
  5. asia pak xx 89
  6. africa tunisia xx
  7. contd
  8. ;
  9. 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.

示例:

  1. data have;
  2. call streaminit(20230417);
  3. do region = 1 to 20;
  4. do customer = 1 to 100+rand('integer', 25);
  5. customerId + 1;
  6. amount = rand('integer', 1, 2500);
  7. output;
  8. end;
  9. end;
  10. keep region customerid amount;
  11. run;
  12. proc means noprint data=have;
  13. class region customerId;
  14. var amount;
  15. types region region*customerId;
  16. output out=summary sum=totalamount;
  17. run;
  18. proc sort data=summary;
  19. by region descending totalamount;
  20. data top10region;
  21. set summary;
  22. where _type_ = 2;
  23. if _n_ > 10 then stop;
  24. run;
  25. data top10c_in_top10r;
  26. merge top10region(rename=totalamount=regiontotal) summary(where=(_type_=3));
  27. by region;
  28. if first.region then regionCount + 1;
  29. if regionCount > 10 then stop;
  30. if first.region
  31. then counter = 1;
  32. else counter + 1;
  33. if counter <= 10 then output;
  34. keep region customerId regionTotal regionTotal totalAmount;
  35. rename totalAmount=customerTotal;
  36. run;

在SAS EG4中,我需要找到按地区排名的前10个国家名称内的前10个客户名称。

英文:

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:

  1. data have;
  2. call streaminit(20230417);
  3. do region = 1 to 20;
  4. do customer = 1 to 100+rand(&#39;integer&#39;, 25);
  5. customerId + 1;
  6. amount = rand(&#39;integer&#39;, 1, 2500);
  7. output;
  8. end;
  9. end;
  10. keep region customerid amount;
  11. run;
  12. proc means noprint data=have;
  13. class region customerId;
  14. var amount;
  15. types region region*customerId;
  16. output out=summary sum=totalamount;
  17. run;
  18. proc sort data=summary;
  19. by region descending totalamount;
  20. data top10region;
  21. set summary;
  22. where _type_ = 2;
  23. if _n_ &gt; 10 then stop;
  24. run;
  25. data top10c_in_top10r;
  26. merge top10region(rename=totalamount=regiontotal) summary(where=(_type_=3));
  27. by region;
  28. if first.region then regionCount + 1;
  29. if regionCount &gt; 10 then stop;
  30. if first.region
  31. then counter = 1;
  32. else counter + 1;
  33. if counter &lt;= 10 then output;
  34. keep region customerId regionTotal regionTotal totalAmount;
  35. rename totalAmount=customerTotal;
  36. run;

在SAS EG4中,我需要找到按地区排名的前10个国家名称内的前10个客户名称。

huangapple
  • 本文由 发表于 2023年4月17日 20:08:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76035007.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定