Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Calculation Assistance

Status
Not open for further replies.

shelby55

Technical User
Jun 27, 2003
1,229
CA
Hello

I received the formula for age in months calculation for SAS but want to convert to the reporting software I'm using (Crystal). However, I don't know what the SAS code is "doing" so if someone could advise I'd appreciate it.

The code is:
age_mths=floor((intck('month',birth_date,date_of_registration)-(day(date_of_registration)<day(birth_date))));

Thanks.
 
OK, breaking the parts down.
floor rounds the value down to a whole number
intck counts the number of defined intervals between the 2 dates. Note that for "month" as shown above, this counts the number of times the 1st of the month appears between the 2 (for year, it's the number of times the 1st of Jan appears etc).
The second part of the equation (after the minus sign) correct for the inaccuracy of the INTCK function. This is a true/false check (is the day of the month of the registration less than the day of the month of the date of birth). True = 1, false = 0, therefore, if the statement is true, a 1 is subtracted from the previous part of the equation. For instance, if the DoB is the 5th of Feb, and the registration date is the 30th of January, the INTCK function will return a value that is 1 higher than it should be, the "TRUE" response in the second half of the equation results in 1 being subtracted to compensate.

I would recommend in this situation to start calculating the age in months in Crystal from scratch as this construction in SAS may not have an analogue in Crystal.


Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top