The Power of the BY Statement
Paul Choate, Toby Dunn
SAS Technical Support Documents, pp. 1-16, 2007
Abstract
When used to its fullest potential, the BY statement can save time and effort, and add clarity and simplicity to SAS programs. It can make complex coding problems simple or accomplish in one pass what would otherwise require multiple passes of the data. Unfortunately the full power of the BY statement is often left unleashed, and instead is relegated to simple mundane everyday work. This paper surveys the basics of the BY statement: the DATA step observation read control statements SET, UPDATE, and MERGE, as well as several basic applications of the BY statement in SAS procedures. Also discussed is how proper data structure will help you unleash the power of the BY statement to gain overall efficiency in your code. The intended audience is beginner and intermediate level SAS programmers.