```Date: Wed, 25 Aug 1999 20:36:45 -0500 Reply-To: shiling@math.wayne.edu Sender: "SAS(r) Discussion" From: Shiling Zhang Organization: Wayne State University Subject: Re: array element count Comments: To: Joshua Muscat Content-Type: text/plain; charset=us-ascii Here is an approach using ordinal function. In each SAS internal looping, 1)sorting the data 2)calculate the freq 3)find largest freq and its value. However, the program will give you a larger(largest) value when the freqs have ties. data t1; array var(10); do i = 1 to 100; do j = 1 to 10; var(j)=ceil(5*ranuni(0)); end; output; end; drop i j; run; data t2; set t1; array _vsort(10); array _freq(10) _temporary_; do i = 1 to 10; _vsort(i)=ordinal(i, of var1-var10); end; _freq(1)=1; do i = 2 to 10; if _vsort(i-1)=_vsort(i) then _freq(i)=_freq(i-1)+1; else _freq(i) =1; end; do i = 1 to 10; if _freq(i) >= max_freq then do; max_freq = _freq(i) ; max_valu = _vsort(i); end; end; drop _vsort1-_vsort10 i; run; Joshua Muscat wrote: > Hi, > > Can some someone describe how to return the most frequent value of the > elements in an array? > > e.g. > > var1 var2 var3 var4 > 1 2 2 3 > > How do you return the value 2? > > thanks very much > > Joshua Muscat, > IPRO ```

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