Article ID: 172084
Article Last Modified on 5/12/2003
* Call this program by ?std("TableName","FieldName") or
* by assigning the result to a variable, y= std("TableName","FieldName")
*
PARAMETER mtable mfield
SELECT SUM(&mfield^2) FROM (mtable) INTO ARRAY yy
SELECT SUM(&mfield)^2 FROM (mtable) INTO ARRAY zz
SELECT COUNT(&mfield) FROM (mtable) INTO ARRAY xx
stdev=((xx*yy-zz)/xx^2)^.5
RETURN ROUND(stdev,12)
If a table named values contains the field num, enter this command in the
Command Window:
?std("values","num")
CLEAR
SET SAFETY OFF
SET DECIMALS TO 12
CREATE TABLE stdresult (num N(15,8)) &&Table for result of calculation
APPEND BLANK
CREATE TABLE stdtest (num N(15,8)) &&Table of values for calculation
FOR i = 1 TO 10
INSERT INTO stdtest(num) VALUES (0.031)
ENDFOR
FOR i = 1 TO RECCOUNT()
?ALLTRIM(STR(i))+" "
SET TALK OFF
CALCULATE STD(num) FOR RECNO()<i TO nresult && Comment this line &
&& the next line once
&& you uncomment the
&& commented lines below.
??nresult
*nresult=custstd('stdresult','num') && Uncomment this line & the next
&& line to compute & display the
&& standard deviation with a
&& user-defined function.
*?nresult
SELECT stdresult
REPLACE num WITH nresult &&Overflow error on 10th iteration
SELECT stdtest
ENDFOR
SET SAFETY ON
SET TALK ON
SET DECIMALS TO 2
PROCEDURE custstd
PARAMETER mtable mfield
SELECT SUM(&mfield^2) FROM (mtable) INTO ARRAY yy
SELECT SUM(&mfield)^2 FROM (mtable) INTO ARRAY zz
SELECT COUNT(&mfield) FROM (mtable) INTO ARRAY xx
stdev=((xx*yy-zz)/xx^2)^.5
RETURN ROUND(stdev,12)
After running this code, the first nine iterations should be all zeroes.
The calculation will be all asterisks and will produce the overflow error
message on the REPLACE command.
Keywords: kbprb kbcode KB172084