| Troy Hughes |
Getters and setters are common in some object-oriented programming (OOP) languages such as C++ and Java, where
“getter” functions retrieve values and “setter” functions initialize (or modify) variables. In Java, for example, getters and
setters are constructed as conduits to private classes, and facilitate data encapsulation by restricting variable access.
Conversely, the SAS® language lacks classes, so SAS global macro variables are typically utilized to maintain and
access data across multiple DATA steps and procedures. Unlike an OOP program that can categorize variables across
multiple user-defined classes, however, SAS maintains only one global symbol table in which global macro variables can
be maintained. Additionally, maintaining and accessing macro variables can be difficult when quotation marks,
ampersands, percentage signs, and other special characters exist in the data. This text introduces user-defined getter
functions and setter subroutines designed using the FCMP procedure, which enable data lookup and initialization
operations to be performed within DATA steps. Among other benefits, user-defined getters and setters can facilitate the
evaluation of complex Boolean logic expressions that leverage data stored across multiple data sets—all concisely
performed in a single SAS statement! Getters and setters are thoroughly demonstrated in the author’s text: PROC FCMP
User-Defined Functions: An Introduction to the SAS® Function Compiler. (Hughes, 2024) |