全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
4508 4
2008-08-01
如何对特定变量值进行加总?
一组数据:
      date              business                  proceeds
01/10/1999       firm A                         123
12/10/1999       firm A                         234
15/10/1999       firm B                          100
17/10/1999       firm C                          200
01/02/2000       firm A                          567
.....
我想把同一个公司的proceeds加总,最后得到的是同一年, 同一家公司只有一条记录.
这样firm A 有两条记录,firmB和firm C各有一条记录.但是对于firmA,proceed 中记录的是两条记录加总的值.




    
二维码

扫码加我 拉你入群

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

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

全部回复
2008-8-1 21:29:00

data pinggu;
infile'd:\sas\sas\pinggu.txt';
input date ddmmyy10. company&$ proceeds;
format date ddmmyy10.;
run;
proc sort data=pinggu;
by company;
run;
data pinggunew;
set pinggu;
by company;
if missing(company) then delete;
if first.company then a=proceeds;
if last.company then do;
a=a+proceeds;
output;
retain a 0;
end;
drop a;
run;
proc print data=pinggunew;
run;

你可以把路径改一下,我测出了结果的,不过就只有这五个数据,更多的数据,我需要再验证才行,希望能给你一点点帮助

二维码

扫码加我 拉你入群

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

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

2008-8-2 22:29:00
echotianxia's solution looks great. But

You can also try the SAS procedures - means, summary, or univariate

The following is the example code for Proc means

data = temp;
  class business datea;
  var proceeds;
  output out = tt sum = sumproceeds;
run;

Note: you probably need to create variable yeara = year (date) and sort the dataset by business and yeara.

Hope it helps !


二维码

扫码加我 拉你入群

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

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

2008-8-2 22:38:00
Assume you have created the new dataset ttt with new variable yeara, the following code will solve your problem:

proc sort data = ttt;
    by business yeara;

proc means NOPRINT
    data = ttt;
    Class business yeara;
    var proceeds;
    output out = new1 sum = sumproceeds;
run;

The output dataset new1 will give you the results.

二维码

扫码加我 拉你入群

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

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

2008-8-3 00:07:00
以下是引用SignPingGu在2008-8-2 22:38:00的发言:
Assume you have created the new dataset ttt with new variable yeara, the following code will solve your problem:

proc sort data = ttt;
    by business yeara;

proc means NOPRINT
    data = ttt;
    Class business yeara;
    var proceeds;
    output out = new1 sum = sumproceeds;
run;

The output dataset new1 will give you the results.

     我觉得既然打算用proc means 或 proc summary了 应该不需要再提前对数据按business 和 yeara排序了。 另外用proc means noprint, 可以直接换成proc summary 就好了。  另外如果只想保留一个business一年只有一条记录,在使用proc summary的时候应该加nway

     proc summary data = ttt nway;
     Class business yeara;
     var proceeds;
     output out = new1 sum = sumproceeds;
     run;

二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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