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 .

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 5 replies
  • 2513 views
  • 0 likes
  • 4 in conversation