turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Newbie question: How use the STD function for matr...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-02-2008 08:02 AM

I am very new with SAS. Something I don't grasp is the following:

I am using IML. I have a matrix like this:

X = {40 1.4 1003,

45 0.8, 1123,

51 1.2 1175,

52 1.1 1014);

I want to compute the standard deviation for every column. There is the STD function. But how can it be used in such a case?

I tried something like this:

STD_X = j(1, ncol(X), -1);

do i=1 to ncol(X);

STD_X[1,i] = std(X[*,i]);

end;

However, this does not work. It seems that the type X[*,i] is no valid argument

for function STD (neither is t(X[*,i])). If I am not mistaken, X[*,i] returns a (sub-) matrix of values whereas STD expects values or variables containing values.

Can't I thus use the STD function?

I am using IML. I have a matrix like this:

X = {40 1.4 1003,

45 0.8, 1123,

51 1.2 1175,

52 1.1 1014);

I want to compute the standard deviation for every column. There is the STD function. But how can it be used in such a case?

I tried something like this:

STD_X = j(1, ncol(X), -1);

do i=1 to ncol(X);

STD_X[1,i] = std(X[*,i]);

end;

However, this does not work. It seems that the type X[*,i] is no valid argument

for function STD (neither is t(X[*,i])). If I am not mistaken, X[*,i] returns a (sub-) matrix of values whereas STD expects values or variables containing values.

Can't I thus use the STD function?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-02-2008 08:08 AM

I don't think the STD function works in IML the way you want it to work.

I think you have to code up the standard deviation formula in IML. I know there is an example somewhere in the IML documentation where the std dev formula is presented in IML code.

I think you have to code up the standard deviation formula in IML. I know there is an example somewhere in the IML documentation where the std dev formula is presented in IML code.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-02-2008 08:55 AM

Ok, thanks for your answer. I just found something in the documentation:

//-----------------------------------------------------------------

Also, SAS/IML software does not support the OF clause of the SAS DATA step. For example, the statement

a=mean(of x1-x10); /* invalid in IML */

cannot be interpreted properly in IML. The term (X1-X10) would be interpreted as subtraction of the two matrix arguments rather than its DATA step meaning, "X1 through X10."

//-----------------------------------------------------------------

It's the same thing with the mean function as with the std function. As it seems, there is no such idea as computing all elements of a matrix row or matrix column at once with those functions. (It however works with others like sum.)

//-----------------------------------------------------------------

Also, SAS/IML software does not support the OF clause of the SAS DATA step. For example, the statement

a=mean(of x1-x10); /* invalid in IML */

cannot be interpreted properly in IML. The term (X1-X10) would be interpreted as subtraction of the two matrix arguments rather than its DATA step meaning, "X1 through X10."

//-----------------------------------------------------------------

It's the same thing with the mean function as with the std function. As it seems, there is no such idea as computing all elements of a matrix row or matrix column at once with those functions. (It however works with others like sum.)

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

10-12-2011 08:59 AM

Since SAS/IML 9.22, IML has supported a VAR function, which computes the variance of each column of a matrix. Use SQRT(VAR(X)) to get the standard deviation.

For how to compute the variance of each column prior to SAS/IML 9.22, see my blog post on "Computing the Variance of Each Column of a Matrix".