Lazy Evaluation: A Comparative Analysis of SAS MACROs and R Functions
This study addresses the lack of systematic comparison between SAS and R regarding their lazy evaluation mechanisms, a gap that hinders cross-language code optimization. It presents the first comprehensive analysis contrasting SAS macros—implemented via symbol-table-based call-by-name—with R functions, which rely on promise-based call-by-need semantics. The work elucidates fundamental differences in evaluation strategies, memory consumption, and execution efficiency, demonstrating their tangible impacts on programming productivity through representative case studies. By clarifying these mechanistic distinctions, the paper provides both theoretical grounding and practical guidance for optimizing code during the transition from SAS to R, particularly in the pharmaceutical industry where such migration is increasingly prevalent.