home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Du Jour
/
SoftwareDuJour.iso
/
BUSINESS
/
DBASE
/
DBAPG.ARC
/
STD-DEV.PRG
< prev
next >
Wrap
Text File
|
1984-08-12
|
2KB
|
70 lines
* Program.: STD-DEV.PRG
* Author..: Luis A. Castro
* Date....: 06/26/84
* Notice..: Copyright 1984, Luis A. Castro, All Rights Reserved
* Version.: dBASE II, version 2.4x
* Notes...: Computes the standard deviation of the records
* of a numeric field in a datafile.
*
SET TALK OFF
ERASE
@ 2, 0 SAY "COMPUTE STANDARD DEVIATION"
@ 2,72 SAY DATE()
@ 3, 0 SAY "========================================"
@ 3,40 SAY "========================================"
ACCEPT "Enter datafile name " TO filename
ACCEPT "Enter numeric field name " TO field:name
STORE !( TRIM(filename) ) + "." TO filename
STORE $(filename,1,@(".",filename)-1) TO filename
IF filename = " " .OR. field:name = " "
SET TALK ON
RETURN
ENDIF
?
USE &filename
IF 0 <= TEST( &field:name )
* ---The field must be numeric and it must exist.
? "INVALID FIELD NAME or FIELD TYPE"
SET TALK ON
RETURN
ENDIF
*
STORE 0 TO items, sum, sumsquare, mean, variance, std:dev
DO WHILE .NOT. EOF
* ---Compute the sum of values and sum of values squared.
STORE sum + &field:name TO sum
STORE sumsquare + ( &field:name * &field:name ) TO sumsquare
STORE items + 1 TO items
?? "."
SKIP
ENDDO
IF items < 2
? "MUST HAVE TWO OR MORE ITEMS TO COMPUTE STANDARD DEVIATION"
SET TALK ON
RETURN
ENDIF
*
* ---Compute mean, variance, and standard deviation.
STORE sum / items TO mean
STORE ( sumsquare - ( sum * sum ) / items ) /;
( items - 1 ) TO variance
IF variance <> 0
* ---Must have a positive number for the square root.
STORE variance TO number
* ---Get the square root of the number.
DO Sqroot
STORE root TO std:dev
ENDIF
*
* ---Output results.
? "RESULTS:"
? "========"
? "NUMBER of items = " + STR( items, 5 )
? "SUM of values = " + STR( sum, 11, 5 )
? "MEAN (average) = " + STR( mean, 11, 5 )
? "VARIANCE = " + STR( variance, 11, 5 )
? "STANDARD DEVIATION = " + STR( std:dev, 11, 5 )
CLEAR
RETURN
* EOF: STD-DEV.PRG