全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
14580 17
2014-11-29
请教大神们:
        下面这个工作该怎么做?怎样剔除第 i家公司之后,计算同行业、同年度的其他公司ROA平均值?
        相关的文献截图如下。万谢!!!

1.jpg

我想用宏命令,基于如下这个方式进行改变,但是结果完全不是自己想要的。请大神把脉!

proc sort data=a;by stkcd year;run;

data a1;set a;
by stkcd;
retain num 0; num=num;/*num=num+0的省略形式*/
if first.stkcd then num=num+1;
run;

proc sort data=a1;by ind year;run;
%macro test;
%do i=1 %to 2574;
proc means data=a1 noprint;
           var roa;by ind year;
                   where &i~=num;
output out=t1(drop=_freq_  _type_) ;run;
%end;
%mend;
%test;



附件列表

a.xls

大小:1.56 MB

 马上下载

数据集

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2014-11-30 10:22:58
TA的数据在哪?
ind代表行业?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-11-30 11:42:30
你的数据集中有两个变量stkcd和Ind,这两个哪个是作为同一行业的标准不太清楚,假如以stkcd作为同一行业的判别变量,再加上year则可以采用sql过程:
复制代码
从你的数据集中我没有看到公司的账面总资产,所以接下来的计算没法进行了。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-12-1 02:55:52
In fact you should re-shape your data first, then using proc means once and only once is a more efficient way and no macro is needed.  An easy example is attached below.



data ind;
  do id=1 to 10;
    x=ranuni(123);
        output;
  end;
run;

data ind2;

do i=1 to nobs;

  set ind nobs=nobs point=i;
   do index=1 to nobs;
     if index ne i then  output;
   end;

end;

stop;
run;

proc means data=ind2 n mean std;
class index;
var x;
run;
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-12-1 09:50:35
mingfeng07 发表于 2014-11-30 11:42
你的数据集中有两个变量stkcd和Ind,这两个哪个是作为同一行业的标准不太清楚,假如以stkcd作为同一行业的判 ...
正解



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2014-12-1 23:05:47
As indicated, you need Total Assets (TA) in the dataset. From the formula, you can use SAS/SQL function of remerging summary statistics back. Jingju

复制代码
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群