楼主: inertialife
4430 4

特定条件加总数据 [推广有奖]

  • 1关注
  • 0粉丝

VIP

本科生

82%

还不是VIP/贵宾

-

威望
0
论坛币
30 个
通用积分
0.0009
学术水平
0 点
热心指数
4 点
信用等级
0 点
经验
1658 点
帖子
127
精华
0
在线时间
93 小时
注册时间
2007-8-7
最后登录
2023-3-31

楼主
inertialife 发表于 2008-8-1 16:28:00 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
如何对特定变量值进行加总?
一组数据:
      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 中记录的是两条记录加总的值.




    
二维码

扫码加我 拉你入群

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

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

关键词:Proceeds Business 同一家公司 FIRM ROCE 数据 条件

回帖推荐

terryw 发表于5楼  查看完整内容

以下是引用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 ...

SignPingGu 发表于3楼  查看完整内容

echotianxia's solution looks great. ButYou can also try the SAS procedures - means, summary, or univariateThe following is the example code for Proc meansdata = 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 !

echotianxia 发表于2楼  查看完整内容

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;你可以把路径改一下,我测出了结果的,不过就只有这五个 ...

本帖被以下文库推荐

沙发
echotianxia 在职认证  发表于 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;

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

已有 1 人评分经验 论坛币 收起 理由
bakoll + 5 + 5 精彩帖子

总评分: 经验 + 5  论坛币 + 5   查看全部评分

藤椅
SignPingGu 发表于 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 !


已有 1 人评分经验 论坛币 收起 理由
bakoll + 5 + 5 精彩帖子

总评分: 经验 + 5  论坛币 + 5   查看全部评分

板凳
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.

报纸
terryw 发表于 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;

已有 1 人评分经验 论坛币 收起 理由
bakoll + 5 + 5 精彩帖子

总评分: 经验 + 5  论坛币 + 5   查看全部评分

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-5 20:11