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!

SAS Dates 2

Status
Not open for further replies.

JamesH122

Technical User
Aug 14, 2007
4
GB
I'm trying to create a variable of an individuals age from a date today variable (SAS format date9.) and a date of birth variable (SAS format datetime).

I've tried the 'intck' statement but the date variables formats seem incompatible.

Can anyone tell me what the best way to go about creating this variable - cheers.
 
Hi James,

Im not 100% sure but im guessing you'll need to cut the date from the datetime field.

Try the below:-

Years = intck('year', datepart(DateTimeVar), DateVar);

Robbie
 
Thanks for that Robbie, worked a treat - much appreciated. Regards James.
 
Hmmm, I posted a response, but when they fixed it by moving your second post to a new thread, they removed my response, so I'd better re-post it.
INTCK is not an adequate method for determining a persons age for the reasons detailed in this article:-

Simply put, the INTCK function only counts the number of times the 1st of the time period chosen occurs between the 2 dates. IE in the previous example using "YEAR", it counts the number of times 1st of January appears between the 2 dates, therefore if todays date is the 2nd of January, and the persons date of birth is the 30th of December last year, they will be given an age of 1 year. This is obviously wrong.
You need to be REALLY cautious when using INTCK.
The article linked above walks you through the steps required to accurately calculate a persons age, and contains it all in a one liner at the end, so I recommmend reading it all the way through.
Cheers.

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

Part and Inventory Search

Sponsor

Back
Top