Вопрос

I am trying to learn a bit about SAS IML programming by through some example code. I'm wondering if anyone could help explain what is happening for this statement?

z=((x=1)*((y=4) || (y=6)));

where, x can be 0 or 1 and y from 1-100

Это было полезно?

Решение

It's a statement that creates a matrix.

First, understand that any = type statements (e.g. x=1 in your case) to the right of your declarative = (z= in your case) are logical statements that return 0 for false and 1 for true.

So, x=1, y=4, and y=6 will all evaluate to a 1x1 matrix with either 0 or 1 in it.

Second, the || is a horizontal concatenation of matrices. Since both sides of the '||' will resolve to a 1x1 matrix, the whole statement ((y=4) || (y=6)) will resolve to a 1x2 matrix.

For instance, if y=4, this will resolve to: ( [1] || [0] ) which will then resolve to [1 0]

Finally, the * is a multiplication operator. So here you are multiplying two matrices. One is a 1x1 matrix (from the (x=1)) and the other is a 1x2 as explained above.

So let's say x=1, this whole thing becomes: z=([1] * [1 0]) which then ends up being z=[1 0]

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top