全部版块 我的主页
论坛 提问 悬赏 求职 新闻 读书 功能一区 悬赏大厅 求助成功区
711 1
2013-05-19
悬赏 5 个论坛币 已解决
举例数据
id   a1    a2    a3    a4   a5
1     2     6     8    9     4
2     5     7     6    3     .
3     4     7     3    2     .
4     7     8     6    .     .


如上面数据,我现在想要所有观测的第一个所测值和最后一个所测值,如id=1第一个所测值=2,最后一个所测值=4,而id=2第一个所测值=5 最后一个所测值为3,以下以此类推。我是个新手,请大家帮忙,非常感谢!

最佳答案

牛妮妮 查看完整内容

data a; input id a1 a2 a3 a4 a5; cards; 1 2 6 8 9 4 2 5 7 6 3 . 3 4 7 3 2 . 4 7 8 6 . . ; run; proc transpose data=a out=b; by id; run; data c; set b; if COL1=. then delete; run; data d; set c; by id notsorted; if first.id then output; if last.id then output; run; proc transpose data=d out=f; by id; run; data g; set f; last=compress(cats(of a3-a5),,'kd'); run; data x; ...
二维码

扫码加我 拉你入群

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

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

全部回复
2013-5-19 00:08:59
data a;
input id a1 a2 a3 a4 a5;
cards;
1 2 6 8 9 4
2 5 7 6 3 .
3 4 7 3 2 .
4 7 8 6 . .
;
run;
proc transpose data=a out=b;
by id;
run;
data c;
set b;
if COL1=. then delete;
run;
data d;
set c;
by id notsorted;
if first.id then output;
if last.id then output;
run;
proc transpose data=d out=f;
by id;
run;
data g;
set f;
last=compress(cats(of a3-a5),,'kd');
run;
data x;
set g;
keep id a1 last;
rename a1=first;
run;
data y;
set x;
newlast=input(last,12.);
run;
data z;
set y;
keep id first newlast;
rename newlast=last;
run;
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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