Date: Mon, 19 May 2008 17:27:32 -0500
Reply-To: Mary <mlhoward@avalon.net>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Mary <mlhoward@AVALON.NET>
Subject: Re: Variance function in IML
Content-Type: text/plain; charset="iso-8859-1"
Cristian,
Here's my condensed version; I can do that in one line :-)
proc iml;
start mod1;
x={10 20 30 40 50};
std=sqrt(sum(((x-j(1,ncol(x),x[:]))##2))/(ncol(x)-1));
print std;
finish;
run mod1;
quit;
run;
-Mary
----- Original Message -----
From: Cristian Gugiu
To: Mary ; SAS-L@LISTSERV.UGA.EDU
Sent: Monday, May 19, 2008 4:18 PM
Subject: Re: Variance function in IML
Per the recommendation of one of the members, I calculated the variance from the sums of squares, as follows
N=nrow(A);
ss=A[##];
sum=A[+];
Var=(ss-(sum**2)/N)/(N-1);
Sd=sqrt(Var);
----- Original Message ----
From: Mary <mlhoward@avalon.net>
To: P. Cristian Gugiu <crisgugiu@YAHOO.COM>; SAS-L@LISTSERV.UGA.EDU
Sent: Monday, May 19, 2008 5:13:36 PM
Subject: Re: Variance function in IML
Christian,
I didn't find where you could do these a variance or standard deviation directly on a matrix (though it seems that you could apply the formula to a matrix with other functions). I did find that you could do it from data sets, and then use the opt{save} option in the summary to save it; the name of the matrix with the results is the variable name.
data test;
infile cards;
input x;
cards;
10
20
30
40
50
run;
proc iml;
start mod1;
use test;
summary var {x} stat{std} opt{save};
print x;
finish;
run mod1;
run;
Producing Summary Statistics
Summary statistics on the numeric variables of a SAS data set can be obtained with the SUMMARY statement. These statistics can be based on subgroups of the data by using the CLASS clause in the SUMMARY statement. The SAVE option in the OPT clause enables you to save the computed statistics in matrices for later perusal. For example, consider the following statement.
> summary var {height weight} class {sex} stat{mean std} opt{save};
SEX Nobs Variable MEAN STD
------------------------------------------------
F 9 HEIGHT 60.58889 5.01833
WEIGHT 90.11111 19.38391
M 9 HEIGHT 64.45556 4.90742
WEIGHT 110.00000 23.84717
All 18 HEIGHT 62.52222 5.20978
WEIGHT 100.05556 23.43382
------------------------------------------------
This summary statement gives the mean and standard deviation of the variables HEIGHT and WEIGHT for the two subgroups (male and female) of the data set CLASS. Since the SAVE option is set, the statistics of the variables are stored in matrices under the name of the corresponding variables, with each column corresponding to a statistic requested and each row corresponding to a subgroup. Two other vectors, SEX and _NOBS_, are created. The vector SEX contains the two distinct values of the class variable SEX used in forming the two subgroups. The vector _NOBS_ has the number of observations in each subgroup.
Note that the combined means and standard deviations of the two subgroups are displayed but are not saved.
More than one class variable can be used, in which case a subgroup is defined by the combination of the values of the class variables.
-Mary
----- Original Message -----
From: P. Cristian Gugiu
To: SAS-L@LISTSERV.UGA.EDU
Sent: Monday, May 19, 2008 3:26 PM
Subject: Variance function in IML
Is there a variance function in IML? I have a matrix A. I am trying to
calculate a 99% CI for the mean value. I know how to get the mean, A[:].
How can I calculate the variance or standard deviation of A? I know I can
save the matrix as a dataset and calculate these summary stats the old-
fashioned way. However, I would prefer to do everything in Iml.
Thanks,
Cristian