BeOptimized - Tips and Tricks

Using SAS arrays, do loops and variable lists

At the era of the big data, it's very common to have lot of variables to manipulate in blocks of variables. Arrays, Do loops and variable lists are powerful data manipulation tools that help make code more efficient for repetitive operation.

Details

SAS arrays are Data Step objects allowing you to group and reference your variables. Once created, the variables of your array are called elements and can be dynamically referenced by their position in the array. This technic is particularly interesting if you have to modify the values of x variables in your dataset, in that case you just have to know the position of your variables in your array to process them. Do loop, allows you to execute statements repetitively. Combining SAS arrays with do loop allows you to treat all the elements dynamically, that is the reason why both topics are often discussed together.
In this tips and tricks we will first talk about the SAS arrays then we will talk about do loop and finally we will combine them !:

  • Creation of SAS array
  • Manipulate SAS array with variable lists and functions
  • Creating a basic do loop
  • Creating do while and do until loop
  • Creating do loop to process all the elements of a list

Then, we will illustrate the theory with several practical examples
  • replace by 0 all the missing numeric variables
  • Comparing values of a dataset with initial values
  • Convert all characters to upcase
  • Create multidimentional array
  • Rotate dataset from wide to narrow
  • Rotate dataset from narrow to wide

Prerequisites

You have some SAS experience and want to use SAS arrays and do loops in order to speed up your code development.


Go back to your selection


This site uses cookies. .

By continuing to browse the site you are agreeing to our use of cookies. Review our cookies information for more details.