|
|||
|
See below.
On Fri, 24 Jun 2005 23:39:22 -0400, Talbot Michael Katz <topkatz@MSN.COM> wrote: >Hi, Roy. > >When using a _temporary_ array it appears that there is NO access to the >var list, only to the array elements. Unfortunately, although you can use > >max(of v1 - v&n.) > > >you can't use > >max(of b{1} - b{&n.}) > > >And it looks like you can use > >max(of c{*}) > > >only when c{} is declared like > >array c{*} var1 - var&n.; > > >and not if you declare > >array c{&n.} var1 - var&n.; > > >But for a _temporary_ array, you have to declare the size > >array t{&n.} _temporary_; > > >In my case, I can certainly find the maximum of the array by keeping track >of the largest element as the array gets initialized, as Kevin Viel >suggested, but what happens after that is that one element of the array >gets modified with each data step iteration. That might change the >maximum. So it seems that, to get the new maximum, I'll either have to >loop through the entire array, or use a macro, as John McQuown suggested, >to generate a list of all the array variables inside the max function. I >suppose another alternative would be to try to keep an ordered version of >the array, but that would need to be re-ordered each time an element >changed, so it's roughly equivalent to looping through the array. It seems to me that you can still keep track of the maximum on a running basis. Here is a demo, with the array being loaded on the first pass, then one element getting changed on each subsequent pass: 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" > >On Fri, 24 Jun 2005 14:28:46 -0700, Pardee, Roy <pardee.r@GHC.ORG> wrote: > >>I guess what I don't understand is how you have a var list to actually >>*populate* the temp array, but you don't have it when time comes to find >>the max value. If your goal is simply to find the max value (and no >>doubt it isn't) you don't need an array at all. >> >>-----Original Message----- >>From: Talbot Michael Katz [mailto:topkatz@MSN.COM] >>Sent: Friday, June 24, 2005 2:20 PM >>To: SAS-L@LISTSERV.UGA.EDU; Pardee, Roy >>Cc: Talbot Michael Katz >>Subject: Re: MAX of _TEMPORARY_ array? >> >> >>Hi, Roy. >> >>Thank you for responding. Yes, >> >>maxa = max(of a1 - a&dima.) ; >> >>works fine for a regular array declared as >> >>array a{*} a1 - a&dima. ; >> >>but what if the array is declared as a _temporary_ array, i.e., >> >>array a{&dima.} _temporary_ ; >> >>Then the variable names in the array, a{}, are not a1 - a&dima.; you >>can't specify them a priori. I think you could retrieve them with CALL >>VNAME, but I'm not sure how that would help. Meanwhile, I haven't found >>a way of using the max function for a _temporary_ array without looping >>through the array (which is what I wanted to avoid, if possible). >> >>-- TMK -- >>"The Macro Klutz" |
|
|
||||
|
||||
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Re: why the array doesn't work | Terry He | Newsgroup comp.soft-sys.sas | 0 | 03-16-2009 04:20 PM |
| Re: weird problem with array name | Arthur Tabachneck | Newsgroup comp.soft-sys.sas | 0 | 11-07-2008 02:32 PM |
| Re: weird problem with array name | Nordlund, Dan | Newsgroup comp.soft-sys.sas | 1 | 11-07-2008 11:06 AM |
| Re: MAX of _TEMPORARY_ array? | Venky Chakravarthy | Newsgroup comp.soft-sys.sas | 0 | 06-27-2005 09:19 PM |
| Re: find maximum vaule in sas array | Paul M. Dorfman | Newsgroup comp.soft-sys.sas | 0 | 04-27-2005 05:27 AM |