|
|
Re: sas一个取最大值的问题[求助,急!!!]
大谢这位前辈!
这段程序连我这种水平都看懂了,感动:)
主要问题都大致解决了~
受教了。
[quote="死猪头":iphbomve]我跟版主是一个师傅教出来的。
[code:iphbomve]
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 sort data=raw out=zhutou;
by company industry year;
run;
data sizhutou(drop=count);
do until (last.industry);
do until(last.year);
set zhutou;
by company industry year;
acum_count = sum(acum_count, count);
end;
random_number = ranuni(12345);
output;
end;
run;
proc sort data=sizhutou out=zhupo;
by company year descending acum_count random_number;
run;
data zhuzai;
do _n_=1 by 1 until(last.year);
set zhupo;
by company year;
if _n_ < 3 then output;
end;
run;
[/code:iphbomve][/quote:iphbomve] |
|