BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
fbl204653
Obsidian | Level 7

Method 1: Age=FLOOR((INTCK('month',dob,eventdate)-(day(eventdate)<day(dob)))/12)

Method 2: Age= INTCK('year',dob,eventdate,"Continuous")

 

Hi I was wondering if two methods above have the same function on calculating Age based on DOB.

 

Thanks a lot

 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

YRDIF actually accepts "AGE" as third argument and returns an age with a fractional part. So

 

floor(YRDIF(birthDate, today(),"AGE"))

 

is another way to get the current age in years.

PG

View solution in original post

5 REPLIES 5
PGStats
Opal | Level 21

No, the results will differ sometimes.

 

Method 2 will give you the exact age. 

Method 1 will sometimes give you the wrong result when eventdate occurs in the same month as dob.

PG
fbl204653
Obsidian | Level 7

Hi PG,

 

I tried one example, somehow, two methods gave me the same result (see age and age2).


%macro age(date,birth);
floor ((intck('month',&birth,&date) - (day(&date) < day(&birth))) / 12)
%mend age;

data c;
WeddingDay='19may2000'd;
Today='18MAY2016'd;
age=%age(Today,WeddingDay);
age1=intck('year',WeddingDay,Today,"D");
age2=intck('year',WeddingDay,Today,"C");
run;

ballardw
Super User

May also want to investigate YRDIF with the 'ACT/ACT' option.

PGStats
Opal | Level 21

YRDIF actually accepts "AGE" as third argument and returns an age with a fractional part. So

 

floor(YRDIF(birthDate, today(),"AGE"))

 

is another way to get the current age in years.

PG
fbl204653
Obsidian | Level 7
thanks a lot

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 8066 views
  • 3 likes
  • 3 in conversation