标题: 怎样在sas中找到特定的数? [打印本页] 作者: shiyiming 时间: 2008-7-12 11:33 标题: 怎样在sas中找到特定的数? 请教大虾一个问题,怎样在一个1*14的sas数据集中,如列名为u1-u14,把其中的某一个赋值给d,做一个循环?以下是我的程序,大虾帮忙看看哪有问题?
data a;
set b;
MaxUr=-1;
j=0;
do i=1 to 14 ;
d=u(i);
if d>maxur then maxur=d;
j=i;
keep MaxUr u1-u14 d;
run;作者: shiyiming 时间: 2008-7-12 12:48 标题: Re: 怎样在sas中找到特定的数? data a;
input u1-u14;
cards;
1 2 3 4 5 6 7 8 9 10 11 12 14 13
;
run;
data b;
retain maxur -1 d 0;
set a;
array u u1-u14;
do over u;
d=u;
if d>maxur then maxur=d;
end;
run;作者: shiyiming 时间: 2008-7-12 16:09 标题: Re: 怎样在sas中找到特定的数? 大虾,换成下面的程序就找不到最大值的位置在哪了。这个程序找到的d=13,正确的应该是10吧。阁下再仔细看一下哪有问题?
data a;
input u1-u14;
cards;
1 2 3 4 5 6 7 8 9 20 11 12 14 13
;
run;
data b;
retain maxur -1 d 0;
set a;
array u u1-u14;
do over u;
d=u;
if d>maxur then maxur=d;
end;
run;作者: shiyiming 时间: 2008-7-12 16:37 标题: Re: 怎样在sas中找到特定的数? data a;
input u1-u14;
cards;
1 2 3 4 5 6 7 8 9 20 11 12 14 13
;
run;
data b;
retain maxur -1 d 0;
set a;
array u u1-u14;
do i=1 to 14 ;
if u{i}>maxur then do;
maxur=u{i};
d=i;
end;
end;
run;
我原来以为d只不过是一个中间变量,现在明白了它是最大值的位置,现在写了一个,您先试一下。作者: shiyiming 时间: 2008-7-12 21:22 标题: Re: 怎样在sas中找到特定的数? 谢谢大虾的回复!