BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

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);
else
maxbal = max(of Bal(num) - Bal(1) , 0 );
1 REPLY 1
RichardH_sas
SAS Employee
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;
    MaxBal=0;

    /* 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};
    end;

    drop i;
    run;

    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!

    http://support.sas.com/forums/forum.jspa?forumID=31
  • sas-innovate-2024.png

    Don't miss out on SAS Innovate - Register now for the FREE Livestream!

    Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

     

    Register now!

    SAS Enterprise Guide vs. SAS Studio

    What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

    Find more tutorials on the SAS Users YouTube channel.

    Click image to register for webinarClick image to register for webinar

    Classroom Training Available!

    Select SAS Training centers are offering in-person courses. View upcoming courses for:

    View all other training opportunities.

    Discussion stats
    • 1 reply
    • 641 views
    • 0 likes
    • 2 in conversation