楼主: inertialife
4708 4

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

  • 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 论坛币
如何对特定变量值进行加总?<br/>一组数据:<br/>      date              business                  proceeds<br/>01/10/1999       firm A                         123<br/>12/10/1999       firm A                         234<br/>15/10/1999       firm B                          100<br/>17/10/1999       firm C                          200<br/>01/02/2000       firm A                          567<br/>.....<br/>我想把同一个公司的proceeds加总,最后得到的是同一年, 同一家公司只有一条记录. <br/>这样firm A 有两条记录,firmB和firm C各有一条记录.但是对于firmA,proceed 中记录的是两条记录加总的值.<br/><br/><br/><br/><br/>      <br/>
二维码

扫码加我 拉你入群

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

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

关键词: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
<p>data pinggu;<br/>infile'd:\sas\sas\pinggu.txt';<br/>input date ddmmyy10. company&amp;$ proceeds;<br/>format date ddmmyy10.;<br/>run;<br/>proc sort data=pinggu;<br/>by company;<br/>run;<br/>data pinggunew;<br/>set pinggu;<br/>by company;<br/>if missing(company) then delete;<br/>if first.company then a=proceeds;<br/>if last.company then do;<br/>a=a+proceeds;<br/>output;<br/>retain a 0;<br/>end;<br/>drop a;<br/>run;<br/>proc print data=pinggunew;<br/>run;</p><p>你可以把路径改一下,我测出了结果的,不过就只有这五个数据,更多的数据,我需要再验证才行,希望能给你一点点帮助</p>
已有 1 人评分经验 论坛币 收起 理由
bakoll + 5 + 5 精彩帖子

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

藤椅
SignPingGu 发表于 2008-8-2 22:29:00
<font face="Verdana" color="#61b713"><b>echotianxia's solution looks great. But<br/><br/></b></font>You can also try the SAS procedures - means, summary, or univariate<br/><br/>The following is the example code for Proc means<br/><br/>data = temp;<br/>  class business datea;<br/>  var proceeds;<br/>  output out = tt sum = sumproceeds;<br/>run;<br/><br/>Note: you probably need to create variable yeara = year (date) and sort the dataset by business and yeara.<br/><br/>Hope it helps !<br/><br/><br/>
已有 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:<br/><br/>proc sort data = ttt;<br/>    by business yeara;<br/><br/>proc means NOPRINT<br/>    data = ttt;<br/>    Class business yeara;<br/>    var proceeds;<br/>    output out = new1 sum = sumproceeds;<br/>run;<br/><br/>The output dataset new1 will give you the results.<br/><br/>

报纸
terryw 发表于 2008-8-3 00:07:00
<div class="quote"><b>以下是引用<i>SignPingGu</i>在2008-8-2 22:38:00的发言:</b><br/>Assume you have created the new dataset ttt with new variable yeara, the following code will solve your problem:<br/><br/>proc sort data = ttt;<br/>&nbsp;&nbsp;&nbsp; by business yeara;<br/><br/>proc means NOPRINT<br/>&nbsp;&nbsp;&nbsp; data = ttt;<br/>&nbsp;&nbsp;&nbsp; Class business yeara;<br/>&nbsp;&nbsp;&nbsp; var proceeds;<br/>&nbsp;&nbsp;&nbsp; output out = new1 sum = sumproceeds;<br/>run;<br/><br/>The output dataset new1 will give you the results.<br/><br/></div><p>&nbsp;&nbsp;&nbsp;&nbsp; 我觉得既然打算用proc means 或 proc summary了 应该不需要再提前对数据按business 和 yeara排序了。 另外用proc means noprint, 可以直接换成proc summary 就好了。&nbsp; 另外如果只想保留一个business一年只有一条记录,在使用proc summary的时候应该加nway</p><p>&nbsp;&nbsp;&nbsp;&nbsp; proc&nbsp;summary&nbsp;data = ttt nway;<br/>&nbsp;&nbsp;&nbsp;&nbsp; Class business yeara;<br/>&nbsp;&nbsp;&nbsp;&nbsp; var proceeds;<br/>&nbsp;&nbsp;&nbsp;&nbsp; output out = new1 sum = sumproceeds;<br/>&nbsp;&nbsp;&nbsp;&nbsp; run;<br/></p>
已有 1 人评分经验 论坛币 收起 理由
bakoll + 5 + 5 精彩帖子

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

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

客服
GMT+8, 2026-12-4 16:46