Date: Mon, 27 Jun 2005 15:06:53 -0400
Reply-To: Sigurd Hermansen <HERMANS1@WESTAT.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Sigurd Hermansen <HERMANS1@WESTAT.COM>
Subject: Re: MAX of _TEMPORARY_ array?
Content-Type: text/plain; charset="us-ascii"
Talbot:
Noting the absence of arraymeisters Paul and Richard from this
discussion, I'll try to step up and pinch hit for them (sort of like
Bellhorn batting for Ramirez or Ortiz). In this case it should take less
time to write a SAS Macro function than to search the many reams of SAS
documentation:
%let DIM=1000000;
%macro maxArray(array=,max=,counter=);
&max.=&array.[1];
do &counter=2 to &DIM;
if &array.[&counter.] > &max. then &max.=&array.[&counter.];
end;
%mend maxArray;
options mprint nosymbolgen;
data _null_;
array a{&DIM} _temporary_ ;
do i = 1 to &DIM;
a{i} = (4*i) - (i*i);
end;
%maxArray(array=a,max=maxa,counter=i)
put maxa= ;
run;
I've made the %maxArray macro more generic than necessary for your
purposes. Resolving the macrovariables will likely take longer than a
search of a relatively large temporary array. The search for the maximum
value takes less than a second to find the max value in an array of
1,000,000 elements. As written, the Macro will work in a wide variety of
situations.
Even so, I'd likely opt for an implicit array (a single-column SAS
dataset). The SAS SQL max() summary function can return the max value in
the column as a macrovariable value.
Sig
-----Original Message-----
From: owner-sas-l@listserv.uga.edu [mailto:owner-sas-l@listserv.uga.edu]
On Behalf Of Talbot Michael Katz
Sent: Friday, June 24, 2005 4:30 PM
To: SAS-L@LISTSERV.UGA.EDU; Mark Terjeson
Cc: Talbot Michael Katz
Subject: Re: MAX of _TEMPORARY_ array?
Hi, Mark.
Thank you for responding. Sorry, this is not what I am looking for at
all. I want the largest value contained in the array. For example:
data _null_;
array a{*} a1-a3;
do i = 1 to 3;
a{i} = (4*i) - (i*i);
end;
maxa = max(of a{*});
put maxa= ;
run;
This will output:
maxa=4
because the values of a{} are a{1} = 3, a{2} = 4, a{3} = 3, and 4 is the
biggest one.
But now try doing this with the array declared as _temporary_, e.g.,
array a{3} _temporary_ ;
and the max function gives an error.
-- TMK --
"The Macro Klutz"