1 data raw;
2 input date yymmdd8. value;
3 format date yymmdd10.;
4 datalines;
NOTE: The data set WORK.RAW has 11 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
16 ;
17 data out;
18 do _n_=1 by 1 until(last.date);
19 set raw;
20 by date;
21 max=max(value,max);
22 end;
23 do _n_=1 to _n_;
24 set raw;
25 output;
26 end;
27 run;
ERROR: BY variables are not properly sorted on data set WORK.RAW.
last.date=0 date=2001-01-04 value=5 FIRST.date=1 max=1 _ERROR_=1 _N_=2
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 10 observations read from the data set WORK.RAW.
NOTE: There were 7 observations read from the data set WORK.RAW.
WARNING: The data set WORK.OUT may be incomplete. When this step was stopped there were 7 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds作者: shiyiming 时间: 2010-8-12 09:37 标题: Re: 找最大值! data raw;
input date yymmdd8. value;
format date yymmdd10.;
datalines;
20010102 8
20010102 1
20010103 5
20010103 3
20010103 5
20010104 1
20010104 5
20010104 12
20010104 8
20010102 3
20010102 5
;
data ex1 ;
if _n_=1 then do;
declare hash h(dataset:'raw', multidata: 'y',ordered:'n');
h.defineKey('date');
h.defineData('date', 'value');
h.defineDone();
/* avoid uninitialized variable notes */
call missing(date,value);
end;
set raw;
rc = h.find();
if (rc = 0) then
do;
max=value;
rc = h.find_next();
do while(rc = 0);
max=max(of max value);
rc = h.find_next();
end;
end;
drop rc;
run;
data ex;
merge ex1 raw ;
run;
proc print;
run;作者: shiyiming 时间: 2010-8-18 01:00 标题: Re: 找最大值! [code:2eqzbbbk]data a;
input g x1-x3;
cards;
20010102 3 1 3
20010102 5 1 5
20010102 8 1 8
20010103 1 2 1
20010103 5 2 5
20010104 3 3 3
20010104 5 3 5
20010104 1 3 1
20010105 5 4 5
20010105 12 4 12
20010105 8 4 8
;
run;
proc sql;
create table aa1(drop=x) as
select *,max(x) as max_x
from (select *,max(x1,x2,x3) as x from a)
group by g;
quit;[/code:2eqzbbbk]
I was confused by why you have to create a variable for group, actually you can treat '20010102,20010103, . . .' themselves as group variable.
And sorry if I misunderstood what you really want.