Calling Other Macros from a Macro
To call other macros from a macro, create a macro definition similar to the following. In this example, the #make_date
macro is nested within the #assign_date
macro, and it is called when #assign_date
runs.
The nested macro must define all, or a subset of, the same parameters that are defined in the base macro. In other words, the input values when the base macro is called must resolve to the parameters in both macros.
The following defines #assign_date
:
MACRO #assign_date PARAMS (#target_col, #year, #month, #day) BEGIN #target_col = #make_date (#year, #month, #day) END;
The following defines #make_date
. This macro creates a date format that includes a four-digit year, after first determining whether the two-digit input date should be prefixed with a century value of 19 or 20. Notice that the PARAMS
statement of #make_date
contains a subset of the parameters in the #assign_date
macro.
MACRO #make_date PARAMS (#year, #month, #day) BEGIN @DATE ('YYYY-MM-DD', 'CC', @IF (#year < 50, 20, 19), 'YY', #year, 'MM', #month, 'DD', #day) END;
The following syntax calls #assign_date
:
#assign_date (COL1, YEAR, MONTH, DAY)
The macro expands to the following given the preceding input values and the embedded #make_date
macro:
COL1 = @DATE ('YYYY-MM-DD', 'CC', @IF (YEAR < 50, 20, 19),'YY', YEAR, 'MM', MONTH, 'DD', DAY)