Next step in the world of SAS IML
In the last article on IML (here) , we introduced you to the world of Matrix language on SAS. We also talked about some basic commands on IML. This article will take you a step further in the same world. After reading this article, you can take up problem solving using SAS IML. In some of the coming articles on IML, we will also take some examples of cases where IML will be very handy.
A Quick Recap
Following code will help you recall all the commands we discussed in the last article. Try guessing the output of the commands before looking at the output below.
A : Original Matrix
B : Transpose of Matrix A
C : Inverse of Matrix A
D : Matrix multiplication of A and B which should ideally be an identity matrix (Using property of Inverse).
Now let’s add a few more types of command on IML in our dictionary.
Replacing elements of a Matrix
In many cases we need to manipulate individual datapoint to fix outliers or missing values. To do this operation in IML, you can use the following method (B has one value replaced while C has an entire column replaced) :
Operation like normalization of probabilities, needs you to collapse one dimension of the matrix. Following code can be used to collapse row or column :
For making any logic, we always need control statements/conditional statements. IML supports all IF-THEN, DO-WHILE, DO-UNTIL statements. Following are a commands which will help you write conditional statements :
Note that in IML, the condition is applied on every element. If element wise operation at all row and column gives a TRUE output, the final output is TRUE. Following is an example of a do-end statement :
Very often we try merging or appending the datasets. IML provides very easy way to do these operations. Following commands can be used for merging (horizontal concatenate) and appending (vertical concatenate) :
Multiple conditions can be used together to form complex conditions on IML. Following is a simple code which demonstrates the same :
This command list was not exhaustive but will definitely enable you to fulfill most of the purposes. In our following articles we will pick up some iterative problems like formulation of Newton-Raphson, Solving Linear Regression, Linear Programming etc. to demonstrate the usage of IML programming.
Did you find the article useful? Have you used IML before? Do you plan to use IML in any of your business problems? If yes, share with us how IML programming will simplify or enable your analysis.
If you like what you just read & want to continue your analytics learning, subscribe to our emails, follow us on twitter or like our facebook page.