The DO Loop
Statistical programming in SAS with an emphasis on SAS/IML programs![Grouping observations based on quantiles](https://blogs.sas.com/content/iml/files/2012/09/grouprank.png)
Sometimes it is useful to group observations based on the values of some variable. Common schemes for grouping include binning and using quantiles. In the binning approach, a variable is divided into k equal intervals, called bins, and each observation is assigned to a bin. In this scheme, the size
![Filling the lower and upper triangular portions of a matrix](https://blogs.sas.com/content/iml/files/2012/09/t_lowertriang.png)
If you use a word three times, it's yours. -Unknown When I was a child, my mother used to encourage me to increase my vocabulary by saying, "If you use a word three times, it's yours for life." I believe that the same saying holds for programming techniques: Use a
![Testing for equality of sets](https://blogs.sas.com/content/iml/files/2012/09/t_seteq.png)
Ah! The joys of sets! It is easy to test whether two vectors are equal in SAS/IML software. It is only slightly more challenging to test whether two sets are equal. Recall that A and B are equal as sets if they contain the same elements. Order does not matter.
![How to return multiple values from a SAS/IML function](https://blogs.sas.com/content/iml/files/2012/08/t_argref.png)
The SAS/IML language supports user-defined functions (also called modules). Many SAS/IML programmers know that you can use the RETURN function to return a value from a user-defined function. For example, the following function returns the sum of each column of matrix: proc iml; start ColSum(M); return( M[+, ] ); /*
![Extract the lower triangular elements of a matrix](https://blogs.sas.com/content/iml/files/2012/08/t_lowertriangular.png)
It is common to want to extract the lower or upper triangular elements of a matrix. For example, if you have a correlation matrix, the lower triangular elements are the nontrivial correlations between variables in your data. As I've written before, you can use the VECH function to extract the
![Visualize the bivariate normal cumulative distribution](https://blogs.sas.com/content/iml/files/2012/07/t_mvnormalcdf.png)
When you are working with probability distributions (normal, Poisson, exponential, and so forth), there are four essential functions that a statistical programmer needs. As I've written before, for common univariate distributions, SAS provides the following functions: the PDF function, which returns the probability density at a given point the CDF