Skip to content

Functions

Chris Swenson edited this page Nov 14, 2020 · 4 revisions

The following macro programs act as functions, and should only be used where functions can be used. For more on these macro programs, see Code Helpers.

  • AgeCalc
    • Calculates age based on a standard, SAS-recommended formula. See this article for more details.
  • BMICalc
    • Calculate BMI based on weight in ounces and height in inches.
  • Convert
    • A function for converting data from numeric to character, character to numeric, date/datetime to character, date to datetime, or datetime to date.
  • CountW
    • Use the COUNTW function in SAS 9.2+ and an alternative in prior versions. Limitation: The macro only uses one delimter at a time. This is useful for dynamic programs to maintain backward compatibility.
  • DatePart
    • Use the DATEPART function, which outputs only the date from a datetime variable, without generating an issue in the log when missing values are encountered. The macro has options to set the output variable name and format, to create a label with information about the source column, and to output a final comma if requested.
  • date_sk
    • Generate date secondary keys. In other words, convert dates into numeric values that look like formatted dates, in either YYYYMM or YYYYMMDD style.

Notes

The following macro programs, listed under Code Helpers, are similar to the above macros in that they output a value, like a function. However, they operate in the macro language itself, not within a DATA or PROC step.