请选择 进入手机版 | 继续访问电脑版
楼主: 神月德
2810 17

数据重复的筛选 [推广有奖]

神月德 发表于 2015-12-12 10:46:34 |显示全部楼层 |坛友微信交流群
67890 发表于 2015-12-12 04:44
sorry, did not finish.

proc sql;
这个可行吗?count(*)是什么意思

使用道具

yafeijojy 发表于 2015-12-12 13:31:56 |显示全部楼层 |坛友微信交流群
神月德 发表于 2015-12-11 21:04
A                                       B
2,2,3,3,4               2,3,4
2,3,3,4,5,5     ...
data a;
input x$11.;
cards;
1,1,2,3,2,4
2,3,2,3,5,6
3,6,8,8,9,0
;run;
%macro a(no);
%do n=1 %to &no;
x&n=scan(x,&n,',')+0;
%end;
%mend a;
data b(drop=x);
set a;
%a(6);
run;
proc transpose data=b out=c;
run;
%macro b(i);
%do n=1 %to &i;
proc sort data=c;
by col&n;
run;
proc sql;
create table col&n as
select distinct col&n from c;
quit;
%end;%mend b;
%b(3)
data me;
merge col1 col2 col3;
run;
proc transpose data=me out=tranpose;
run;
data want;
set tranpose;
array x(5) col1-col5;
do i=1 to 5;
if x(i)=. then x(i)='';
m=x(1)||','||x(2)||','||x(3)||','||x(4)||','||x(5);
m=compress(m,'.');
m=compress(m);end;
run;

这个可以,但是写的太长了,效率不高,希望能有更加优化的code。

使用道具

yongyitian 发表于 2015-12-13 00:32:37 |显示全部楼层 |坛友微信交流群
data have;
   a ="2, 2, 3, 3, 4   "; output;
   a ="2, 3, 3, 4, 5, 5"; output;
   a ="3, 6, 8, 8, 9, 0"; output;
run;

data have1;
   set have;
   do i = 1 to countw(a);
    b1 = scan(a,i);
    output;
   end; drop i;
run;

proc sql;
    create table have2 as
    select distinct a, b1
    from have1
    group by a
    order by a, b1;
quit;

data wanted;
    set have2;
    by a;
      length b $20;
      retain b;
    if first.a then b=b1;
    else b = cats(b, ",", b1);
    if last.a then output;
    drop b1;
run;

MP762-Remove duplicated words in an observation.JPG

使用道具

yafeijojy 发表于 2015-12-13 14:03:28 |显示全部楼层 |坛友微信交流群
yongyitian 发表于 2015-12-13 00:32
data have;
   a ="2, 2, 3, 3, 4   "; output;
   a ="2, 3, 3, 4, 5, 5"; output;
果然好用

使用道具

kandkula 发表于 2015-12-14 15:49:58 |显示全部楼层 |坛友微信交流群
67890 发表于 2015-12-12 04:44
sorry, did not finish.

proc sql;
这样是对一个ID有多条记录的处理,好像理解错了,貌似不能解决lz的问题。

使用道具

kandkula 发表于 2015-12-14 15:53:21 |显示全部楼层 |坛友微信交流群
神月德 发表于 2015-12-12 10:46
这个可行吗?count(*)是什么意思
对每个ID count 记录的个数

使用道具

神月德 发表于 2015-12-14 21:26:52 |显示全部楼层 |坛友微信交流群
yongyitian 发表于 2015-12-13 00:32
data have;
   a ="2, 2, 3, 3, 4   "; output;
   a ="2, 3, 3, 4, 5, 5"; output;
你这个比较好懂,请问countw()函数是什么意思

使用道具

yongyitian 发表于 2015-12-15 10:16:39 |显示全部楼层 |坛友微信交流群

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-3-29 04:02