1
PharmaSUG 2021 - Paper AP-151
Using PROC FCMP to Create Custom Functions in SAS
Keith Shusterman and Mario Widel, Reata Pharmaceuticals Inc.
ABSTRACT
PROC FCMP is a powerful but somehow underused tool that can be leveraged for creating custom
functions. While macros are of vital importance to SAS programming, there are many situations where
creating a custom function can be more desirable than using a macro. Particularly, custom functions
created through PROC FCMP can be used in other SAS procedures such as PROC SQL, PROC PRINT,
or PROC FREQ. As an alternate approach to SAS macros, PROC FCMP can be used to create custom
functions that process character and numeric date and datetime values. In this presentation, we will
share two custom functions created using PROC FCMP. The first creates ISO 8601 character values from
raw date inputs, and the second creates numeric SAS dates and datetimes from ISO 8601 inputs. We
will also show how these newly created custom functions can be called in other SAS procedures.
INTRODUCTION
In SAS Version 5, the SAS/TOOLKIT software was used to create custom SAS functions. Use of this
software was limited to programmers experienced in programming in C, PL/I, FORTRAN, or IBM 370
assembler languages. Fortunately, SAS today has a procedure specifically for defining custom functions,
and it can be used by programmers who know how to program a SAS data step.
The SAS Function Compiler (FCMP) Procedure is used to create and store custom SAS functions and
subroutines. The syntax is very similar to that of the SAS DATA step language, with several small
variants. The custom functions and subroutines created by PROC FCMP can be used in other SAS
procedures.
SAS FUNCTIONS AND SUBROUTINES
The SAS 9.4 reference defines a function as a block of code that takes arguments and returns a single
value, either character or numeric, as output. In contrast, it defines a CALL routine as a block of code
that can alter variables or perform other system functions. While it’s important to note that while PROC
FCMP can compile CALL routines, this paper will specifically focus on functions.
We will show that custom functions created with PROC FCMP are able to alter variables called as input
arguments but this is not best practice in the authors’ opinion for reasons discussed below.
SYNTAX
PROC FCMP uses the following statements:
proc fcmp options;
declaration statements;
program statements;
One commonly used option is the OUTLIB option, which allows the user to store the function in a physical
location. Once compiled and stored, the function can then be called from any other SAS program using
the SAS global option CMPLIB.