BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
moreka
Obsidian | Level 7

I am trying to find the maximum of several variables (ml1-ml9), which are broken up into a before and after group, defined by the value in variable 'before'.

If before=3 then find the maximum of ml1-ml3 and then of ml4-ml9.

If before=6 then find the maximum of ml1-ml6 and then of ml6-ml9.

I tried to do this inside of an array, but unless I'm writing the do loop or array incorrectly, the max function doesn't appear to work in this context:

  data amt;  set dom;  bef=0;

  array ml(9) ml1-ml9;

  do j=1 to before;

  bef+ml(j);

  maxbef=max(of ml(j));

                      ---

            71

ERROR 71-185: The MAX function call does not have enough arguments.

What better ways might there be to do this?  My other thought was subsetting the data into Before and After datasets with an array by deleting irrelevant data.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

I think you are just going to have to get loopy to meet your requirements.

data amt; 

  set dom; 

  array ml(9) ml1-ml9;

  do j=1 to before;

    MAXBEF = MAX(0,MAXBEF,ml(j));

  end;

  do j=before+1 to dim(ml);

    MAXAFTER = MAX(0,MAXAFTER,ml(j));

  end;

run;

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

I think you are just going to have to get loopy to meet your requirements.

data amt; 

  set dom; 

  array ml(9) ml1-ml9;

  do j=1 to before;

    MAXBEF = MAX(0,MAXBEF,ml(j));

  end;

  do j=before+1 to dim(ml);

    MAXAFTER = MAX(0,MAXAFTER,ml(j));

  end;

run;

moreka
Obsidian | Level 7

Brilliant, thanks!

Ksharp
Super User

Why not use two simple statements ?

MAXBEF = MAX(of ml1-ml4);

MAXAFTER = MAX(of ml4-ml9);

Haikuo
Onyx | Level 15

I think 'Before' is a variable whose values may change across obs. Tom's approach is more robust, no more "if ... then" needed.

Haikuo

Ksharp
Super User

Agree. I need take a look closer .

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 3226 views
  • 0 likes
  • 4 in conversation