The DO Loop
Statistical programming in SAS with an emphasis on SAS/IML programs![Beware the naked LOC](https://blogs.sas.com/content/iml/files/2017/01/AdvancedAnalytics-2.png)
The LOC function is one of the most important functions in the SAS/IML language. The LOC function finds elements of a vector or matrix that satisfy some condition. For example, if you are going to apply a logarithmic transform to data, you can use the LOC function to find all
![Constructing block matrices with applications to mixed models](https://blogs.sas.com/content/iml/files/2012/11/blockmatrix.png)
The other day I was constructing covariance matrices for simulating data for a mixed model with repeated measurements. I was using the SAS/IML BLOCK function to build up the "R-side" covariance matrix from smaller blocks. The matrix I was constructing was block-diagonal and looked like this: The matrix represents a
![Compute the log-determinant of a matrix](https://blogs.sas.com/content/iml/files/2012/10/t_logdet.png)
The determinant of a matrix arises in many statistical computations, such as in estimating parameters that fit a distribution to multivariate data. For example, if you are using a log-likelihood function to fit a multivariate normal distribution, the formula for the log-likelihood involves the expression log(det(Σ)), where Σ is the
![Playing "craps" with unfair dice](https://blogs.sas.com/content/iml/files/2012/10/unfaircraps.png)
Last week I wrote a SAS/IML program that computes the odds of winning the game of craps. I noted that the program remains valid even if the dice are not fair. For convenience, here is a SAS/IML function that computes the probability of winning at craps, given the probability vector
![Dice probabilities and the game of "craps"](https://blogs.sas.com/content/iml/files/2012/10/t_craps1.png)
Gambling games that use dice, such as the game of "craps," are often used to demonstrate the laws of probability. For two dice, the possible rolls and probability of each roll are usually represented by a matrix. Consequently, the SAS/IML language makes it easy to compute the probabilities of various
![A surprising result: The expected number of uniform variates whose sum exceeds one](https://blogs.sas.com/content/iml/files/2012/09/minexceed.png)
I was recently flipping through Ross' Simulation (2006, 4th Edition) and saw the following exercise: Let N be the minimum number of draws from a uniform distribution [until the sum of the variates]exceeds 1. What is the expected value of N? Write a simulation to estimate the expected value. For