In a previous blog, I demonstrated a program and macro that could identify all numeric variables set to a specific value, such as 999. and %DO_OVER macros are analogous to the ARRAY and DO OVER statements in the SAS data step language, which define and loop over implicitly subscripted arrays. Example 3 - Using DO OVER to Simplify your DO Loops with Arrays To alleviate the need for manual counting of array elements, SAS also provides the DO OVER loop option to work with non-indexed arrays. For a complete guide on SAS DO LOOPs, see The Complete Guide to Do-loop, Do-while and Do-Until found here. For each iteration of the DO loops, SAS substitutes the value of the array element corresponding to the current values of I and J. The syntax in the DATA step is to specify a list of values (numeric or character) after the equal sign. Temporary array elements are automatically retained, instead of being reset to missing at the beginning of the next iteration of the DATA step. We call those kinds of loops iterative DO loops. The macros use regular characters as much as possible, For example, when the subscript is a number (not the asterisk), you do not need to name each variable in the array. The names must be either variables that you define in the ARRAY statement or variables that SAS creates by concatenating the array name and a number. The actions of some DO loops are unconditional in that if you tell SAS to do something 20 times, SAS will do it 20 times regardless. As you start building larger arrays with more and more variables, non-indexed arrays can be a helpful tool. Dim and Range. The macros use regular characters as much A SAS array name is just one way to reference a group of variables that you want to have treated as though it was like an array. The names must be either variables that you define in the ARRAY statement or variables that SAS creates by concatenating the array name and a number. You will often see SAS programmers use the dim function in a Do Loop because it lets them iterate over each element in an array.. The Range Function takes a list of values as argument and returns the difference between the largest and the smallest value. The %ARRAY and %DO_OVER macros are analogous to the ARRAY and DO OVER statements in the SAS® data step language, which define and loop over implicitly subscripted arrays. The Dim Function is quite simple. So anytime you use the reference BONDS, SAS will expect you to use a subscript or index, such as BONDS(1) (which points to X1) or BONDS(2) (which points to X2). The outer DO loop (DO I=1 TO 2) processes the inner DO loop twice. SAS doesn't support that syntax directly, but there is a variant of the DO loop in which you can iterate over values in a specified list. When programming, you can find yourself needing to tell SAS to execute the same statements over and over again. 1 SAS #SASGF ® GLOBAL FORUM 2020 Paper 4419-2020 A Beginner’s Guide to Using ARRAYs and DO Loops Jennifer L. Waller, Augusta University, Augusta, GA ABSTRACT If you are copying and pasting code over and over to perform the same operation on Although they behave like variables, temporary array elements do not have names, and they do not appear in the output data set. Because these macros are self-contained and use global macro variables, you can use them freely in “open code”. That's when a DO loop can come in and save your day. For example, when the subscript is a number (not the asterisk), you do not need to name each variable in the array. To create a temporary array, use the _TEMPORARY_ argument. The most commonly used array type is the explicit SAS Array, which can be broken down into 6 main components: array array-name {X} $ length array-elements initial-values This blog discusses an immensely useful technique that allows you to perform an operation on all numeric or all character variables in a SAS data set. Because these macros are self-contained and use global macro variables, you can use them freely in “open code”. It returns the number of elements in an array. The inner DO loop (DO J=1 TO 5) applies the ROUND function to all the variables in one row. First, let’s walkthrough the different components of a SAS array. Next, let us look at the Dim and Range Functions.