From: Church on
I want to calculate the standard deviation of the elements of a vector
in proc iml. I expected a standard function for this, but I can't find
this. I found the function STD, but it seems to require several
arguments (not in a vector form).
Anyone?

Of course, I could also calculate the standard deviation myself, but I
want to use standard functionality as much as possible.
From: xlr82sas on
On Apr 13, 1:29 pm, Church <H.J.P...(a)uva.nl> wrote:
> I want to calculate the standard deviation of the elements of a vector
> in proc iml. I expected a standard function for this, but I can't find
> this. I found the function STD, but it seems to require several
> arguments (not in a vector form).
> Anyone?
>
> Of course, I could also calculate the standard deviation myself, but I
> want to use standard functionality as much as possible.

Here are IML and R solutions ( I have not used IML in a while, but the
last time I used it it did not have a standard deviation function)

R is much easier. (I am a hack at R but learning - removing the
interface - there is only one line of R code )

data have;
input id case1 case2;
cards;
1 1 1
1 1 1
6 6 16
1 1 1
1 1 1
;
run;


%rsetup; /* set up the SAS R interface
*/
data
_null_;
length pgm
$1024;
call
putxpt('have');
/* R CODE
*/

pgm=compbl("

library(SASxport);

library(foreign);
x<-read.xport('C:\\utl\\have.xpt');

stdev<-data.frame(c(sd(x$CASE1),sd(x$CASE2)));

write.xport(stdev,file='C:\\utl\
\stdev.xpt',autogen.formats=FALSE);

");
/* EXECUTE R CODE
*/
call
rxeq(pgm);
call
getxpt('stdev');
run;

Obs C_SD_X_C

1 2.23607
2 6.70820

=================================================================================

IML

proc iml;
use have;
read all var {case1 case2} into sqd[ colname=vars ];
sqd[,1:2]=(sqd[,1:2] - sqd[+,1:2]/nrow(sqd));
print sqd;
sqd=sqrt(sqd[##,]/(nrow(sqd)-1));
print sqd;
create stdev from sqd;
append from sqd;
run;quit;

proc print data=stdev;
run;

The SAS System

Obs COL1 COL2

1 2.23607 6.70820