全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1624 6
2011-08-22
我有一组数据,
原有数据                                    期望数据
1                                                       1                  
2                                                       2
2                                                       2
3                                                       3
6                                                       6
3                                                       .
3                                                       .
3                                                       .
5                                                       5
6                                                       .
6                                                       .
6                                                       .
6                                                       .
8                                                       8
我想去掉三个以上连续一样的数据,把他们的值改成missing value .想问具体怎么实现,谢谢
二维码

扫码加我 拉你入群

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

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

全部回复
2011-8-22 08:28:52
Running the program below will give you the desired results.


data t1;
input x;
cards;
1
2
2
3
6
3
3
3
5
6
6
6
6
8
;

data t2;
   do i=1 by 1 until(last.x);
      set t1;
          by x notsorted;
          if first.x then cnt=0;
          cnt+1;
   end;
   do i=0 by 1 until(last.x);
      set t1;
          by x notsorted;
          x_old=x;
          if cnt>=3 then x=.;
          output;
   end;
   keep x x_old;
run;

proc print;run;
二维码

扫码加我 拉你入群

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

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

2011-8-22 16:56:48
data a;
input a;
n=_n_;
cards;
1
2
2
3
6
3
3
3
5
6
6
6
6
8
;
run;

proc sql;
create table b as
select a,case when count(*)>=3 then .
else  a
end as b from a
group by a
order by n
;
quit;
二维码

扫码加我 拉你入群

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

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

2011-8-23 01:26:13
bobguy 发表于 2011-8-22 08:28
Running the program below will give you the desired results.
原来first. last. unsorted 还有这么大的用处,学习了
二维码

扫码加我 拉你入群

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

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

2011-8-23 01:27:47
honghejing 发表于 2011-8-22 16:56
data a;
input a;
n=_n_;
非常感谢,学到了不同的思路
二维码

扫码加我 拉你入群

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

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

2011-8-23 07:50:21
honghejing 发表于 2011-8-22 16:56
data a;
input a;
n=_n_;
The result is not EXACT what he wanted. I believe it is not quite easy to use SQL solving this problem because SQL is not designed to handle data sequentially.
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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