A. Extract Month, Year information from DateTime.
- Convert DateTime to Date using Datepart() first.
- Use Year() and Month() function to get the Month and Year information
date=datepart(datetime); year=year(date); month=month(date);
B. Date Value for Date Comparison
- ’17OCT1991’D is 11612, and is SAS date Oct. 17, 1991
- use single quotation and D at the end
- the day, month, or year in the date string can be replaced by macro variable to become dynamic. eg. ’01JUL&yr.” can be used for comparison of July 1 of different year.
C. Age calculation
- Reference: https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-calculate-age-from-Date-of-birth-and-date-of-last-visit/td-p/572236
- Reference: https://blogs.sas.com/content/iml/2017/05/15/intck-intnx-intervals-sas.html
- intck function results whole year and yrdif function results decimal year.
- In intck function, using the ‘continuous’ or ‘c’ option to return the number of full years.
age = intck('Year', birth, "01JUL&yr."D, 'C');