Online File

#### Chapter 48 Program Data step formulas for descriptive statistics

```data _null_;
retain;
set a (keep=a) end=last;
if missing(a) then nmiss + 1;
else do;
n + 1;
sum + a;
uss + a*a;
sc + a*a*a;
sf + a*a*a*a;
if min = . then min = a;
min = min min a;
max = max max a;
end;
if last then do;
if n >= 1 then do;
range = max - min;
mean = sum/n;
css = uss - mean*sum;
end;
if n >= 2 then do;
var = css/(n - 1);
std = sqrt(var);
stderr = sqrt(var/n);
if mean then cv = 100*std/mean;
if std then do;
if n >= 3 then skewness =
(sc - 3*mean*uss + 2*mean*mean*sum)
/ (var*std) * n/((n - 1)*(n - 2));
if n >= 4 then kurtosis = (sf - 4*mean*sc
+ 6*mean*mean*uss - 3*mean*mean*mean*sum)
/ (var*var) * n*(n + 1)/((n - 1)*(n - 2)*(n - 3))
- 3*(n - 1)*(n - 1)/((n - 2)*(n - 3));
t = mean/stderr;
prt = 2*probt(-abs(t), n - 1);
end;
end;
put 'Descriptive Statistics Calculated In A Data Step' //
n= / nmiss= / min= / max= / range= /
sum= / mean= / uss= / css= / var= / std= / stderr= /
cv= / skewness= / kurtosis= / t= / prt= ;
end;
run;
```