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.
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;
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;
Brilliant, thanks!
Why not use two simple statements ?
MAXBEF = MAX(of ml1-ml4);
MAXAFTER = MAX(of ml4-ml9);
I think 'Before' is a variable whose values may change across obs. Tom's approach is more robust, no more "if ... then" needed.
Haikuo
Agree. I need take a look closer .
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!
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.