The DO Loop
Statistical programming in SAS with an emphasis on SAS/IML programs![Use the FLOOR-MOD trick to allocate items to groups](https://blogs.sas.com/content/iml/files/2017/01/ProgrammingTips-2.png)
Suppose you need to assign 100 patients equally among 3 treatment groups in a clinical study. Obviously, an equal allocation is impossible because the second number does not evenly divide the first, but you can get close by assigning 34 patients to one group and 33 to the others. Mathematically,
![Convergence in mixed models: When the estimated G matrix is not positive definite](https://blogs.sas.com/content/iml/files/2019/04/Gnotposdef.png)
I've previously written about how to deal with nonconvergence when fitting generalized linear regression models. Most generalized linear and mixed models use an iterative optimization process, such as maximum likelihood estimation, to fit parameters. The optimization might not converge, either because the initial guess is poor or because the model
![Matrix operations and BY groups](https://blogs.sas.com/content/iml/files/2019/04/ByGroupSim2-640x336.png)
Many SAS procedures support the BY statement, which enables you to perform an analysis for subgroups of the data set. Although the SAS/IML language does not have a built-in "BY statement," there are various techniques that enable you to perform a BY-group analysis. The two I use most often are
![How to simulate multivariate outliers](https://blogs.sas.com/content/iml/files/2019/03/MVOutliers6-400x336.png)
In simulation studies, sometimes you need to simulate outliers. For example, in a simulation study of regression techniques, you might want to generate outliers in the explanatory variables to see how the technique handles high-leverage points. This article shows how to generate outliers in multivariate normal data that are a
![The geometry of multivariate versus univariate outliers Schematic diagram of outliers in bivariate normal data. The point 'A' has large univariate z scores but a small Mahalanobis distance. The point 'B' has a large Mahalanobis distance. Only 'b' is a multivariate outlier.](https://blogs.sas.com/content/iml/files/2019/03/MVOutliers1-702x336.png)
An important concept in multivariate statistical analysis is the Mahalanobis distance. The Mahalanobis distance provides a way to measure how far away an observation is from the center of a sample while accounting for correlations in the data. The Mahalanobis distance is a good way to detect outliers in multivariate
![Truncate response surfaces](https://blogs.sas.com/content/iml/files/2019/03/rsreg3-400x336.png)
An analyst was using SAS to analyze some data from an experiment. He noticed that the response variable is always positive (such as volume, size, or weight), but his statistical model predicts some negative responses. He posted the data and asked if it is possible to modify the graph so