Desktop productivity for business analysts and programmers

Max function and array

Not applicable
Posts: 0

Max function and array


Is it possible to find the maximum entry in an array using max function?? The problem is that at each record, there is a different starting point in the array. e,g,

Array Bal(36) balance1-balance36;

if num > 18 then
maxbal = max(of Bal(num) - Bal(num-18), 0);
maxbal = max(of Bal(num) - Bal(1) , 0 );
SAS Employee
Posts: 149

Re: Max function and array

Posted in reply to deleted_user
I'm sure there are multiple good solutions here. Since the MAX function isn't too fancy, I actually found it easier to write some code that avoids using the function.

%let levels=18;
/* Setting this up as a macro variable
makes it easy to change */

data test;
set whatever;
array Bal
  • balance1-balance36;

    /* Create lower limit for DO loop */
    if num >= &levels then
    bottom = num - &levels + 1;
    else bottom = 1;

    /* Cycle from bottom to the value of num */
    do i = bottom to num;
    if Bal{i} > MaxBal then
    MaxBal = Bal{i};

    drop i;

    In the future, you might have a little more luck posting to the DATA step board for responses on topics like this. No worries though!
  • Ask a Question
    Discussion stats
    • 1 reply
    • 2 in conversation