hi,
try this code for calculating it:-
REPORT abc. DATA : BEGIN OF itab OCCURS 0, num TYPE i, END OF itab. data : std type p decimals 2. *------------------------------------------------- itab-num = 8. APPEND itab. itab-num = 25. APPEND itab. itab-num = 7. APPEND itab. itab-num = 5. APPEND itab. itab-num = 8. APPEND itab. itab-num = 3. APPEND itab. itab-num = 10. APPEND itab. itab-num = 12. APPEND itab. itab-num = 9. APPEND itab. PERFORM stdev changing std.. write :/ std. *------------------------------------------------- *------------------------------------------------- *------------------------------------------------- FORM stdev CHANGING std. DATA : mn TYPE p DECIMALS 2. DATA : sm TYPE i. DATA : sm2 TYPE i. DATA : dev TYPE p DECIMALS 2. DATA : cnt TYPE i. LOOP AT itab. sm = sm + itab-num. cnt = cnt + 1. sm2 = sm2 + ( itab-num * itab-num ). ENDLOOP. mn = sm / cnt. dev = ( sm2 - ( ( ( sm * sm ) / cnt ) ) ) / ( cnt - 1 ) . dev = SQRT( dev ). std = dev. ENDFORM. "stdev
Edited by: ricx .s on May 2, 2009 1:50 PM
Edited by: ricx .s on May 2, 2009 1:51 PM
REPORT YP_STD_DEVIATION.
DATA : BEGIN OF ITAB OCCURS 0,
NUM TYPE I,
END OF ITAB.
DATA : STD TYPE P DECIMALS 2.
*-------------------------------------------------
ITAB-NUM = 9. APPEND ITAB.
ITAB-NUM = 2. APPEND ITAB.
ITAB-NUM = 5. APPEND ITAB.
ITAB-NUM = 4. APPEND ITAB.
ITAB-NUM = 12. APPEND ITAB.
ITAB-NUM = 7. APPEND ITAB.
ITAB-NUM = 8. APPEND ITAB.
ITAB-NUM = 11. APPEND ITAB.
PERFORM STDEV CHANGING STD..
WRITE :/ STD.
*-------------------------------------------------
*-------------------------------------------------
*-------------------------------------------------
FORM STDEV CHANGING STD.
DATA : MEAN TYPE P DECIMALS 2.
DATA : CSUM TYPE I. "Count Sum
DATA : SM1 TYPE I.
DATA : NSSUM TYPE I."Net Sqre Sum
DATA : DEV TYPE P DECIMALS 2.
DATA : CNT TYPE I.
**Mean = Sum of X values / N(Number of values)
LOOP AT ITAB.
CSUM = CSUM + ITAB-NUM.
CNT = CNT + 1.
"NSS = NSS + ( ITAB-NUM * ITAB-NUM ).
ENDLOOP.
MEAN = CSUM / CNT.
** "Find the variance,
"square all, Add all the Squared numbers
LOOP AT ITAB.
SM1 = ITAB-NUM - MEAN.
NSSUM = NSSUM + ( SM1 * SM1 ).
ENDLOOP.
BREAK-POINT.
**
DEV = 1 / CNT * NSSUM.
DEV = SQRT( DEV ).
STD = DEV.
ENDFORM. "stdev
Add a comment