Stephen,
Below is a macro I wrote a long time ago that would give you back two arrays:
the sorted input values and an array of rank percents. You would have to get
all values, pass then as an array to this macro, get the returned arrays,
then used those arrays as you loop through the records to look up the value
in the value array (use ArrayPosition()), and get the rank percent and store
it in the record.
Larry Manire
---------------------------------------------------
macro 'order_method_get_rank_pcts' (vals) // rev 91
// receives list of values, sorts them, and create an output array of pairs
of
// elements containing the unique value and the average rank percent the
value is
// of the total original values.
// This procedure is useful when there are runs of values.
// Eg., the values 1,3,3,3,5 return the array {{1,20.0}, {3,50.0}, {5,
100.0}}
// if only 1 value then return
if vals.length=1 then return({{vals[1]}, {100.0}})
// sort the values
vals=sortarray(vals)
// find the unique values
knt=1 // contains total occurences for current unique value
upct_total=1/vals.length*100 // cumulative percentage for the unique value
uval=vals[1]
uvals=null // array to contain unique values
upcts=null // array to contain avg pct of each unique val
for i=2 to vals.length do
// found another of the same unique value
if vals[i]=uval then do
upct_total=upct_total+(i/vals.length*100)
knt=knt+1
end else do
// found next unique value; output previous and reset
upct=(upct_total/knt) // average of all pcts for this unique value
uvals=uvals+{uval}
upcts=upcts+{upct}
uval=vals[i]
knt=1
upct_total=i/vals.length*100
end
end
upct=(upct_total/knt)
uvals=uvals+{uval}
upcts=upcts+{upct}
return({uvals, upcts})
endmacro
--------------------------------------------------------
--
Open WebMail Project (http://openwebmail.org)
---------- Original Message -----------
From: "sjones_sc" <[EMAIL PROTECTED]>
To: [email protected]
Sent: Fri, 16 Dec 2005 03:05:08 -0000
Subject: [Maptitude] DK code to accurately rank records
> I need to write code that will take a column of values, sort them,
> and fill another column with sequenced 'ranked' values. Now, the
> HARD part is that the regular method of SetRecordsValues with a
> sequence {1,1} of values isn't exactly accurate. And the counter=0,
> counter = counter + 1 loop is the same as the SetRecordsValues. The
> problem with those methods is this...if two consectutive records
> have the same value, they aren't ranked the same b/c it is a simple
> fill sequence method. So, for example, open a view and sort by
> population field, and if records 2 and 3 each have a value of 25000,
> record 2 is ranked 2 and record 3 is ranked 3, where actually, they
> should both be ranked 2 (or 2.5). I have immersed myself in
> multiple array loops and have officially gone off the deep-end.
> Anybody have any ideas??
>
> Thanks in advance for any help.
>
> Stephen
>
> ------------------------ Yahoo! Groups Sponsor --------------------~-->
> Get fast access to your favorite Yahoo! Groups. Make Yahoo! your
> home page http://us.click.yahoo.com/dpRU5A/wUILAA/yQLSAA/C5grlB/TM
> --------------------------------------------------------------------~->
>
> Yahoo! Groups Links
>
>
>
------- End of Original Message -------
------------------------ Yahoo! Groups Sponsor --------------------~-->
Get fast access to your favorite Yahoo! Groups. Make Yahoo! your home page
http://us.click.yahoo.com/dpRU5A/wUILAA/yQLSAA/C5grlB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/Maptitude/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/