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

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

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;

在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:

data have;
  call streaminit(20230417);

  do region = 1 to 20;
    do customer = 1 to 100+rand(&#39;integer&#39;, 25);
      customerId + 1;
      amount = rand(&#39;integer&#39;, 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_ &gt; 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 &gt; 10 then stop;

  if first.region 
    then counter = 1;
    else counter + 1;

  if counter &lt;= 10 then output;

  keep region customerId regionTotal regionTotal totalAmount;
  rename totalAmount=customerTotal;
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:

确定