How to resolve the algorithm Cumulative standard deviation step by step in the SAS programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Cumulative standard deviation step by step in the SAS programming language

Table of Contents

Problem Statement

Write a stateful function, class, generator or co-routine that takes a series of floating point numbers, one at a time, and returns the running standard deviation of the series. The task implementation should use the most natural programming style of those listed for the function in the implementation language; the task must state which is being used. Do not apply Bessel's correction; the returned standard deviation should always be computed as if the sample seen so far is the entire population.

Use this to compute the standard deviation of this demonstration set,

{ 2 , 4 , 4 , 4 , 5 , 5 , 7 , 9 }

{\displaystyle {2,4,4,4,5,5,7,9}}

, which is

2

{\displaystyle 2}

.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Cumulative standard deviation step by step in the SAS programming language

Source code in the sas programming language

*--Load the test data;
data test1;
   input x @@;
   obs=_n_;
datalines;
2 4 4 4 5 5 7 9
;
run;

*--Create a dataset with the cummulative data for each set of data for which the SD should be calculated;
data test2 (drop=i obs);
   set test1;
   y=x;
   do i=1 to n;
      set test1 (rename=(obs=setid)) nobs=n point=i;
      if obs<=setid then output;
   end;
proc sort;
   by setid;
run;

*--Calulate the standards deviation (and mean) using PROC MEANS;
proc means data=test2 vardef=n noprint; *--use vardef=n option to calculate the population SD;
   by setid;
   var y;
   output out=stat1 n=n mean=mean std=sd;
run;

*--Output the calculated standard deviations;
proc print data=stat1 noobs;
   var n sd /*mean*/;
run;


  

You may also check:How to resolve the algorithm Shell one-liner step by step in the Nim programming language
You may also check:How to resolve the algorithm Guess the number/With feedback step by step in the NetRexx programming language
You may also check:How to resolve the algorithm Mayan numerals step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Palindrome detection step by step in the C programming language
You may also check:How to resolve the algorithm Factorial step by step in the Peloton programming language