Date: Mon, 27 Jun 2005 14:24:15 -0400 "Howard Schreier " "SAS(r) Discussion" "Howard Schreier " Re: MAX of _TEMPORARY_ array?

Yup. The "running max" would be an all-time max, not a max of the current population.

David: Take note and reset my most-recent-mistake timer :-)

On Mon, 27 Jun 2005 13:46:50 -0400, Talbot Michael Katz <topkatz@MSN.COM> wrote:

>Hi, Howard. > >Thank you for the suggestion. Your particular example may have worked, but >it appears to me that your construction won't always work. If I understand >correctly, "high" is supposed to keep the current maximum of the array. >Here is a very small example. Suppose my array is a{1} = 5, a{2} = 4, a{3} >= 2; we should have high = 5. Now, suppose my next iteration changes a{1} >to 3. The comparison in runningmax keeps high = 5, but 5 is no longer the >maximum of the array. Even if you try to keep track of the array index at >which the maximum is achieved, you'll still need to know the next highest >current value, and the strategy will fail anyway, because there may be ties >for the maximum. It's tricky to keep a running maximum, unless your >changes are never subtractions; if you always increase, then I think your >method will work. > >> data _null_; >> set sashelp.class; >> array ta(19) _temporary_; >> >> if _n_=1 then do i = 1 to 19; >> ta(i) = floor(ranuni(1)*10); >> link runningmax; >> end; >> >> i = _n_; >> ta(i) = age; >> link runningmax; >> >> return; >> >> runningmax: >> retain high; >> high = max(high,ta(i) ); >> put _n_= high=; >> return; >> >> run; >> > > >-- TMK -- >"The Macro Klutz"

Back to: Top of message | Previous page | Main SAS-L page