The DO Loop
Statistical programming in SAS with an emphasis on SAS/IML programs![Cosine similarity of vectors](https://blogs.sas.com/content/iml/files/2019/08/cosSim4-640x336.png)
An important application of the dot product (inner product) of two vectors is to determine the angle between the vectors. If u and v are two vectors, then cos(θ) = (u ⋅ v) / (|u| |v|) You could apply the inverse cosine function if you wanted to find θ in
![Annotate features of a schematic box plot in SGPLOT](https://blogs.sas.com/content/iml/files/2019/08/boxschematic2-300x336.png)
A SAS programmer asked an intriguing question on the SAS Support Communities: Can you use SAS to create a graph that shows how the elements in a box-and-whiskers plot relate to the data? The SAS documentation has several examples that explain how to read a box plot. One of the
![Conditionally append observations to a SAS data set](https://blogs.sas.com/content/iml/files/2019/08/dataappend1-343x336.png)
Most SAS programmers know how to use PROC APPEND or the SET statement in DATA step to unconditionally append new observations to an existing data set. However, sometimes you need to scan the data to determine whether or not to append observations. In this situation, many SAS programmers choose one
![Two tips for optimizing a function that has a restricted domain](https://blogs.sas.com/content/iml/files/2019/08/fitparamdata1-640x336.png)
An important application of nonlinear optimization is finding parameters of a model that fit data. For some models, the parameters are constrained by the data. A canonical example is the maximum likelihood estimation of a so-called "threshold parameter" for the three-parameter lognormal distribution. For this distribution, the objective function is
![Timing performance in SAS/IML: Built-in functions versus Base SAS functions](https://blogs.sas.com/content/iml/files/2019/08/timeMissing-640x336.png)
One of my friends likes to remind me that "there is no such thing as a free lunch," which he abbreviates by "TINSTAAFL" (or TANSTAAFL). The TINSTAAFL principle applies to computer programming because you often end up paying a cost (in performance) when you call a convenience function that simplifies
![Short-circuit evaluation and logical ligatures in SAS](https://blogs.sas.com/content/iml/files/2017/01/ProgrammingTips-2.png)
Many programmers are familiar with "short-circuit" evaluation in an IF-THEN statement. Short circuit means that a program does not evaluate the remainder of a logical expression if the value of the expression is already logically determined. The SAS DATA step supports short-circuiting for simple logical expressions in IF-THEN statements and