[bit.listserv.sas-l] squaring std's in a type=cov data set

alderton@NPRDC.NAVY.MIL (David Alderton) (02/09/90)

Folks,
   I posted a note yesterday about squaring the _numeric_ values of
a _type_='std' in a type=cov data set.  A few suggestions were made but
most people asked me for more information.  Below is the code is I
working with.  I need 4 quantities:  (a) the sum of all the elements
in the covariance matrix (sumc below), (b) number of subjects in the
data set (n below), (c) the number of items entering into the covariance
set (k below), and (d) the sum of the variances (sumv below).  I can get
the first three quantities but haven't been successful getting the sum
of the variances.  More accurately, I cannot get the standard deviations
squared to sum them up.  I tried an array but couldn't figure out how to
address the _numeric_ elements, and then tried a few variants of directly
squaring _numeric_ elements with no success in either case.  Here are two
things that I tried:
    1.   if _type_='std' then sumv+sum(of ( _numeric_ * _numeric_ ))-sumc**2;
    2.   if _type_='std' then sumv+sum(of ( _numeric_)**2)-sumc**2;
Both these attempts produce errors, (1) function not known, (2) name
exceeds 8 characters.
   This is driving me crazy!!!  Can anyone help me out with this?

Thanks,
   David.
=====================SAS V. 5.18 on an IBM 4381 running CMS==============
options center nocaps ls=72;
cms filedef in disk brad2 raw a;
data one;
   infile in;
   input idac1-idac3;
proc corr data=one cov noprint out=cov (type=cov);
data cov;
   set cov end=endin;
   retain sumc 0 sumv 0 n k;
     if _type_='cov' then sumc+sum(of _numeric_)-sumc;
1.   if _type_='std' then sumv+sum(of ( _numeric_ * _numeric_ ))-sumc**2;
2.   if _type_='std' then sumv+sum(of ( _numeric_)**2)-sumc**2;
     if _type_='n' then n=(sum(of _numeric_)-sumc-sumv)/
                            (n(of _numeric_)-2);
     if _type_='n' then k=n(of _numeric_)-3;
     if endin=1 then do;
        alpha = (k/(k-1))*(1-(sumv/sumc));
        output;
     end;
   run;
data calcf;
   set cov;
     f = (1-0)/(1-alpha);
     fprob2 = 1 - probf(of f, n-1, (n-1)*(k-1));
proc print data=calcf;
   var alpha n k f fprob;

HAMER@VCUVAX.BITNET (ROBERT M. HAMER) (02/09/90)

<alderton@nprdc.navy.mil> writes:

>   I posted a note yesterday about squaring the _numeric_ values of
>a _type_='std' in a type=cov data set.  A few suggestions were made but
>most people asked me for more information.  Below is the code is I
>working with.  I need 4 quantities:  (a) the sum of all the elements
>in the covariance matrix (sumc below), (b) number of subjects in the
>data set (n below), (c) the number of items entering into the covariance

>set (k below), and (d) the sum of the variances (sumv below).  I can get
>the first three quantities but haven't been successful getting the sum
>of the variances.  More accurately, I cannot get the standard deviations

I am still not at all sure I understand what you want, because your
ends and your means seem to be two different things.  You say that want you
want is (and I quote exactly) "the sum of the variances."

The variances are the diagonal elements of a covariance matrix, so if
you want the sum of the variances, you want to go through the covariance
matrix, line by line, figure out what line you are on, get to the
variable corresponding to that line, pick off the variance, and increment
your accumulator.  You could use array's for that, but in a very
different way from the way you tried to.