Reputation: 57
I am currently sourcing data in SAS EG 6.1 to get the min and max values based on the observation. Now I need to be able to grab the minimum value out of an array where only included in the array are numbers >= 90.
data MinMaxRows;
set tbl4;
where EvalDt1 <> .;
array x(3) date1-date3;
max_value=max(of x(*));
min_value=min(of x(*));
run;
Upvotes: 0
Views: 130
Reputation: 63424
If you want to do this with a single function, you can always use FCMP (in 9.4+, I think 9.3 it won't accept a non-temporary array):
proc fcmp outlib=work.funcs.func;
function minMin(min,num[*]);
curMin = constant('BIG');
do _i = 1 to dim(num);
if num[_i] ge min and num[_i] lt curMin then
curMin = num[_i];
end;
if curMin < constant('BIG') then
return(curMin);
else return(.);
endsub;
quit;
options cmplib=work.funcs;
data test;
array x[3];
x[1]=4;
x[2]=11;
x[3]=15;
x_min=min(of x[*]);
x_min_10 = minMin(10,x);
put x_min= x_min_10=;
run;
Upvotes: 1
Reputation: 7769
Drop any values less than 90, then perform the min()
and max()
:
data want ; set have ; array dt{*} date1-date3 ; do i = 1 to dim(dt) ; dt{i} = ifn(dt{i} < 90 , . , dt{i}) ; end ; dtmax = max(of dt:) ; dtmin = min(of dt:) ; run ;
Upvotes: 0
Reputation: 21264
There's always the 'manual' way...ie search through the array.
data want;
set tbl4;
array crit(3) crit1-crit3;
array date(3) date1-date3;
crit_max90=.;
crit_index90=.;
do i=1 to dim(crit);
if crit(i)>90 and crit(i)>crit_max90 then do;
crit_max90=crit(i);
crit_index90=i;
end;
end;
run;
Upvotes: 1
Reputation: 481
Sounds like you need to create another array with your criteria of 90 that corresponds to the date. This is what I'm envisioning your data looking like:
data &wl.tbl4;
infile datalines;
input @1 date1 mmddyy10.
@10 date2 mmddyy10.
@19 date3 mmddyy10.
@28 Evaldt1 mmddyy10.
@37 crit1
@40 crit2
@43 crit3;
format date1--evaldt1 mmddyy10.;
datalines;
1/1/2016 1/2/2016 1/3/2016 1/1/2016 85 90 95
;
run;
And this is what you would use to apply that criteria to your array:
data MinMaxRows;
set tbl4;
where EvalDt1 <> .;
array x(3) date1-date3;
array x_90(3) _temporary_;
array crit(3) crit1-crit3;
do i = 1 to 3;
if crit(i) >= 90 then x_90(i) = x(i);
end;
format max_value min_value max_value_90 min_value_90 mmddyy10.;
max_value=max(of x(*));
min_value=min(of x(*));
max_value_90=max(of x_90(*));
min_value_90=min(of x_90(*));
run;
Upvotes: 2