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.
Disclaimer: The SAS macros on this site are provided "as-is". The user is responsible for testing the code on their platform. The user agrees that the author will not, under any circumstances, be held accountable for any damages of any type that result from using these macros. Please review the license provided with the programs.
- Home
- Categories
- Documentation
- Send Feedback [External]
- Christopher A. Swenson
- About & Contact [External]
- Professional Samples [External]
- Resume [External]
- References [External]
- Blog [External]