楼主: cxsyb
1782 5

[原创博文] 新手请教sas中对数据集的问题 [推广有奖]

  • 0关注
  • 0粉丝

大专生

30%

还不是VIP/贵宾

-

威望
0
论坛币
73 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
532 点
帖子
54
精华
0
在线时间
19 小时
注册时间
2006-8-7
最后登录
2014-12-19

楼主
cxsyb 发表于 2009-9-18 20:18:50 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
想请教下如下数据
id                 a      b   c
001              1     2    3
001              2     3   4
002              2     5    1
002              3      2   1
怎么样把 相同id的1行和2行加总,3 行和4 行加总?
得到 id   a    b   c
         001  3  5   7
         002  5  7  2
谢谢指教
二维码

扫码加我 拉你入群

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

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

关键词:数据集 怎么样

回帖推荐

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

data x; input id $ a b c@; cards; 001 1 2 3 001 2 3 4 002 2 5 1 002 3 2 1 ;run; proc sql noprint; create table final as select id,sum(a) as a,sum(b) as b, sum(c) as c from x group by id;quit;

luijb 发表于4楼  查看完整内容

楼上的程序比较简洁,我来段复杂的吧,也是数据量比较大的时候能用的上。 data raw; input id $3. a b c; cards; 001 1 2 3 001 2 3 4 002 2 5 1 002 3 2 1 ; proc sort data=raw; by id; data result(drop=a b c i); set raw; by id; retain a1 b1 c1 0; array aa(3) a b c; array bb(3) a1 b1 c1; do i=1 to 3; bb(i)+aa(i); if first.id then bb(i)=aa(i); end; if last.id; ru ...

本帖被以下文库推荐

沙发
cxsyb 发表于 2009-9-18 20:37:25
会的说下啊,,处理一组数据时遇到这样的问题,不知道怎么整了
在线等待,谢谢

藤椅
xiaosanmao 发表于 2009-9-18 20:49:09
cxsyb 发表于 2009-9-18 20:37
会的说下啊,,处理一组数据时遇到这样的问题,不知道怎么整了
在线等待,谢谢
data x;
input id $ a      b   c@;
cards;
001              1     2    3
001              2     3   4
002              2     5    1
002              3      2   1
;run;
proc sql noprint;
create table final as
select id,sum(a) as a,sum(b) as b,
sum(c) as c from x group by id;quit;
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

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

板凳
luijb 在职认证  发表于 2009-9-19 10:02:07
楼上的程序比较简洁,我来段复杂的吧,也是数据量比较大的时候能用的上。
data raw;
input id $3.  a b c;
cards;
001   1   2   3
001   2   3   4
002   2   5   1
002   3   2   1
;
proc sort data=raw;
by id;
data result(drop=a b c i);
set raw;
by id;
retain a1 b1 c1 0;
array aa(3) a b c;
array bb(3) a1 b1 c1;
do i=1 to 3;
bb(i)+aa(i);
if first.id then bb(i)=aa(i);
end;
if last.id;
run;
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

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

西格玛临床统计服务工作室http://www.sigma-stat.com/,luijb@163.com

报纸
cxsyb 发表于 2009-9-19 10:16:12
感谢两位
谢谢

地板
pandasasa 发表于 2009-10-12 00:55:22
data aa;
input id $6.0 a b c;
infile datalines truncover;
datalines;
001              1     2    3
001              2     3  4
002              2     5    1
002              3      2   1
; run;
data b;
do _n_=1 by 1 until(last.id);
set aa;
by id;
if first.id then do; suma=0; sumb=0 ; sumc=0;end;
suma+a;
sumb+b;
sumc+c;
end;
run;

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

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