home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!caen!uakari.primate.wisc.edu!zazen!news
- From: dly@vms.macc.wisc.edu
- Newsgroups: comp.databases
- Subject: PARADOX, procedure to calculate median
- Message-ID: <1992Jul23.145939.21048@macc.wisc.edu>
- Date: 23 Jul 92 14:56:35 GMT
- Sender: news@macc.wisc.edu (USENET News System)
- Organization: University of Wisconsin Academic Computing Center
- Lines: 60
-
- I am new to PARADOX, and I needed to figure out a way that users could
- have a median on a numeric column calculated for them. I came up with
- this procedure which works, but it is very BRUTE force. If there are
- other users who have ideas on how to streamline this, please let me know.
-
- Thanks!
- Debbie Yoshihara
- DLY@MACC.WISC.EDU
-
- 1) First I set up SHIFT-F1 in a miniscript:
- SETKEY "F11" PLAY "MEDIAN"
-
- 2) Then VIEW a table, and TAB to the field where you would like a median
- and press SHIFT-F1
-
- 3) The results will be shown in the ANSWER table.
-
- 4) Here is the Procedure:
-
- PROC MEDIAN(TBLNAME,FLDNAME)
- IF FIELDTYPE() <> "N" THEN
- MESSAGE "ERROR IN PROCESSING: You must select a numeric field!"
- SLEEP 2000
- RETURN
- ENDIF
- IF FLDNAME = "#" THEN
- MESSAGE "ERROR IN PROCESSING: You cannot select the # field!"
- SLEEP 2000
- RETURN
- ENDIF
- SORT TBLNAME ON FLDNAME TO "ZZZTEMP"
- HOWMANY = CCOUNT("ZZZTEMP",FLDNAME)
- MIDPLACE = HOWMANY/2
- MODVAL = MOD(HOWMANY,2)
- EDIT "ZZZTEMP"
- MOVETO RECORD MIDPLACE
- MOVETO FIELD FLDNAME
- VALUE1 = []
- MOVETO RECORD MIDPLACE+1
- MOVETO FIELD FLDNAME
- VALUE2 = []
- DO_IT!
- DELETE "ZZZTEMP"
- DO_IT!
- NEWFLD = "MEDIAN OF " + FLDNAME
- CREATE "ANSWER" NEWFLD : "N"
- EDIT "ANSWER"
- MOVETO FIELD NEWFLD
- IF MODVAL=0 THEN
- [ANSWER -> ] = (VALUE1+VALUE2)/2
- ELSE
- [ANSWER -> ] = VALUE1
- ENDIF
- DO_IT!
- RETURN
- ENDPROC
-
- TBLNAME = TABLE()
- FLDNAME = FIELD()
- MEDIAN(TBLNAME,FLDNAME)
-