The DO Loop
Statistical programming in SAS with an emphasis on SAS/IML programs![The GCD and LCM functions in SAS](https://blogs.sas.com/content/iml/files/2013/11/t_gcd.png)
My daughter's middle school math class recently reviewed how to compute the greatest common factor (GCF) and the least common multiple (LCM) of a set of integers. (The GCF is sometimes called the greatest common divisor, or GCD.) Both algorithms require factoring integers into a product of primes. While helping
![Square root transformations: How to handle negative data values?](https://blogs.sas.com/content/iml/files/2013/10/t_sqrtxform.png)
I was looking at someone else's SAS/IML program when I saw this line of code: y = sqrt(x<>0); The statement uses the element maximum operator (<>) in the SAS/IML language to make sure that negative value are never passed to the square root function. This little trick is a real
![How to order categories in a two-way table with PROC FREQ](https://blogs.sas.com/content/iml/files/2013/10/t_orderfreq.png)
If you've ever tried to use PROC FREQ to create a frequency table of two character variables, you know that by default the categories for each variable are displayed in alphabetical order. A different order is sometimes more useful. For example, consider the following two-way table for the smoking status
![Output percentiles of multiple variables in a tabular format Output percentiles in a tabular format in SAS](https://blogs.sas.com/content/iml/files/2017/02/t_pctls6.png)
A challenge for statistical programmers is getting data into the right form for analysis. For graphing or analyzing data, sometimes the "wide format" (each subject is represented by one row and many variables) is required, but other times the "long format" (observations for each subject span multiple rows) is more
![Assign the diagonal elements of a matrix](https://blogs.sas.com/content/iml/files/2017/02/AdvancedAnalytics-4.png)
SAS/IML programmers know that the VECDIAG matrix can be used to extract the diagonal elements of a matrix. For example, the following statements extract the diagonal of a 3 x 3 matrix: proc iml; m = {1 2 3, 4 5 6, 7 8 9}; v = vecdiag(m); /* v = {1,5,9}
![Rotating matrices](https://blogs.sas.com/content/iml/files/2013/10/rot90.png)
This article is about rotating matrices. No, I don't mean "rotation matrices," I mean rotating matrices. As in turning a matrix 90 degrees in a clockwise or counterclockwise direction. I was reading a program written in MATLAB in which the programmer used a MATLAB function called ROT90, which rotates a