Calculating Median

brian_matthewsbrian matthews brian_matthews_bmw@hotmail.com
Thu, 12 Aug 2004 00:13:07 +0000


Hi all,

we got Pete's option working using the code below.  We did'nt know if it 
actually runs as Peter coded it - ie could it be one of the Mpe magical 
coding efficiences - or was it a novel kind of 'simplifying' code 
presentation. We also got Joe's suggestion going after a bit of a rethink, 
but we think the OS calls might be slower, and simply think that Peter's 
code is more elegant.


can clear

set default
acc EMPS_P_DICT

define preset_0p5 = -0.5
define preset_1 = 0

define half_1_a = 0.5
define half_1_b = 0.5

define d-Phone_No  int*15 = nconv(Phone_No)

sort on d-Phone_No a

select if d-Phone_No ne 0

report summary d-Phone_No x-count subtotal noreset  &
half_1_a subtotal initial preset_0p5  noreset  half_1_b subtotal initial 
preset_1  noreset

set subfile name xsub keep

build pete1

can clear

set default

set rep dev term

access *xsub link to record ( half_1_a of xsub) of *xsub alias low &
              link to record ( half_1_b of xsub) of *xsub alias high

define median num * 18 = (  D-PHONE_NO of low +  D-PHONE_NO of high ) / 2

Final Footing median

build pete2



The code we used for Joe's suggestion is below,


can clear

set default

acc EMPS_P_DICT alias mydets

define d-Phone_No  int*15 = nconv(Phone_No)

select if d-Phone_No ne 0

define d-add int * 17 = nconve(getsystemval("myadd1")) if record mydets 
exists

define d-val int = 1 if d-Phone_No ne 0

define d-myput2 int *10 = 1 if (setsystemval("myadd1", ascii( d-add + d-val 
) ) ) &
and (d-Phone_No ne 0 )

sort on d-Phone_No a

define d-recordlocation int*10 = 1

set sub nam xsubj keep

rep summ d-Phone_No d-recordlocation subtot noreset

build joe1

can clear

set default

acc * xsubj

define myget int *10 = nconve(getsystemval("myadd1"))

define d-num-recs = mod (myget,2)

define d-rec1 =  myget/2  if d-num-recs = 0 else ceiling ( myget/2 )

define d-rec2 =  d-rec1 + 1 if d-num-recs = 0 else ceiling ( myget/2 )

select if d-rec1 = d-recordlocation or d-rec2 = d-recordlocation

define d-divider = 2 if d-num-recs = 0 else 1
define d-value int * 16 = d-Phone_No / d-divider

sorted on d-Phone_No

fin foot d-value subtot

build joe2

_________________________________________________________________
Use MSN Messenger to send music and pics to your friends 
http://www.msn.co.uk/messenger