LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (August 1999, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 25 Aug 1999 20:36:45 -0500
Reply-To:     shiling@math.wayne.edu
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Shiling Zhang <shiling@MATH.WAYNE.EDU>
Organization: Wayne State University
Subject:      Re: array element count
Comments: To: Joshua Muscat <jmuscat@EARTHLINK.NET>
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