SAS中文论坛
标题:
【求助】SAS关于一行中的重复观测问题
[打印本页]
作者:
shiyiming
时间:
2013-2-6 12:18
标题:
【求助】SAS关于一行中的重复观测问题
各位大侠,你们好!
马上要过年了,但有一个问题让我非常头疼,望大侠指点
有12个数字变量,现需每行中12个数据里面的不重复的数据打印出来。
例如:
data a;
input a1-a12;
cards;
5 18 22 28 29 31 12 13 19 22 28 29
1 3 4 6 7 8 5 6 7 10 12 13
.....
就是说第一行中22,28和29有重复的,所以只取其中的9个变量(5,12,13,18,19,22,28,29,31)
第二行中6和7是重复的,所以取10个变量,这个问题是在不知从何入手,望大家帮忙。
作者:
shiyiming
时间:
2013-2-7 20:38
标题:
Re: 【求助】SAS关于一行中的重复观测问题
[code:1f56hdsu]data a;
input a1-a12;
cards;
5 18 22 28 29 31 12 13 19 22 28 29
1 3 4 6 7 8 5 6 7 10 12 13
;
run;
data aa;
set a;
array a a1-a12;
array aa aa1-aa12;
s=0;
do i=1 to 12;
do j=1 to i-1;
if a{i}=a{j} then s=1;
end;
if s=0 then aa{i}=a{i};
s=0;
end;
run;[/code:1f56hdsu]
作者:
shiyiming
时间:
2013-2-10 16:23
标题:
Re: 【求助】SAS关于一行中的重复观测问题
[code:ukli15y5]
data a;
input a1-a12;
cards;
5 18 22 28 29 31 12 13 19 22 28 29
1 3 4 6 7 8 5 6 7 10 12 13
;
data _null_;
set a end=last nobs=tot;
if last then call symput("tot",tot);
run;
proc transpose data=a out=b(drop=_NAME_);
run;
%macro nodupvar;
%local i;
%do i=1 %to &tot.;
data c;
set b(keep=col1);
run;
proc sort data=c out=d nodupkey;
by col1;
run;
data _null_;
set d end=last nobs=num;
if last then call symput("num_of_&i.th_row",num);
run;
%end;
%put _user_;
%mend nodupvar;
%nodupvar
[/code:ukli15y5]
欢迎光临 SAS中文论坛 (http://www.mysas.net/forum/)
Powered by Discuz! X3.2