|
|
7#

楼主 |
发表于 2010-8-23 15:53:10
|
只看该作者
Re: sas一个取最大值的问题[求助,急!!!]
我不确定是否实现了在并列值中随机排序,你测试看看吧
[code:2x1rsbjo]data raw;
length COMPANY $1 YEAR $4 INDUSTRY $40;
input;
COMPANY=scan(_infile_,1,' ');
YEAR=scan(_infile_,2,' ');
INDUSTRY=substr(_infile_,8,anydigit(_infile_,8)-9);
COUNT=input(scan(_infile_,-1,' '),best.);
datalines;
A 1999 Communications and Media 1
A 1999 Computer Software and Services 1
A 1999 Internet Specific 5
A 2000 Communications and Media 1
A 2000 Computer Software and Services 7
A 2000 Internet Specific 1
A 2001 Communications and Media 1
A 2001 Computer Software and Services 1
A 2001 Internet Specific 1
B 1999 Biotechnology 8
B 1999 Communications and Media 7
B 1999 Computer Hardware 2
B 1999 Computer Software and Services 23
B 1999 Consumer Related 23
B 1999 Industrial/Energy 12
B 1999 Internet Specific 21
B 1999 Medical/Health 7
B 1999 Other Products 34
B 1999 Semiconductors/Other Elect. 5
B 2000 Biotechnology 13
B 2000 Communications and Media 14
B 2000 Computer Hardware 5
B 2000 Computer Software and Services 34
B 2000 Consumer Related 12
B 2000 Industrial/Energy 19
B 2000 Internet Specific 56
B 2000 Medical/Health 11
B 2000 Other Products 25
B 2000 Semiconductors/Other Elect. 3
;
proc transpose data=raw out=temp(drop=_name_);
var count;
by company year;
id industry;
run;
data temp(drop=i);
do _n_=1 by 1 until(last.company);
set temp;
by company;
array industry_count_ {*} _numeric_;
array temp {10} _temporary_;
do i=1 to dim(industry_count_);
industry_count_(i)=sum(ifn(missing(industry_count_(i)),0,industry_count_(i)),temp(i));
temp(i)=industry_count_(i);
end;
output;
end;
run;
data temp(keep=company year industry_count_1 industry_count_2 industry_name_1 industry_name_2);
set temp;
array temp {*} _numeric_;
array industry_count_ {10};
array industry_name_ {10} $32;
flag=ceil(ranuni(0)*10);
do i=1 to dim(industry_count_);
j=i+ifn(i ge flag,-flag,10-flag)+1;
industry_count_(j)=temp(i);
call vname(temp(i),industry_name_(j));
end;
do i=dim(industry_count_)-1 to 1 by -1;
do j=1 to i;
if industry_count_(j+1) gt industry_count_(j) then do;
temp_num=industry_count_(j);
industry_count_(j)=industry_count_(j+1);
industry_count_(j+1)=temp_num;
temp_chr=industry_name_(j);
industry_name_(j)=industry_name_(j+1);
industry_name_(j+1)=temp_chr;
end;
end;
end;
run;[/code:2x1rsbjo] |
|