BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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?
3 REPLIES 3
Paige
Quartz | Level 8
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.
deleted_user
Not applicable
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.)
Rick_SAS
SAS Super FREQ

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".

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 822 views
  • 0 likes
  • 3 in conversation