BookmarkSubscribeRSS Feed
ybz12003
Rhodochrosite | Level 12

Hello:

 

I have a code below to compute the age.   I am trying to figure out what this codes are for. 

 

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

	Age_calc = %age(screendate, DOB);
age = round(Age_calc);

 

Or better codes to do this? 

3 REPLIES 3
ballardw
Super User

Depends somewhat on how you want the age but the typical use of age can be

 

age = floor ( yrdif (DOB, comparedate, 'AGE'));

 

if you want an integer age. Without the the FLOOR function to round down you get a decimal value.

 

 

The current macro, which has been around a long time it is calculating the months between two dates with the INTCK function and then if the day of the month is before the day of month of birth subtracting one month, then divides that by 12 to get approximate year and truncates that result to remove the decimal portion by rounding down.

PGStats
Opal | Level 21

No reason to define a macro anymore, you might as well call the INTCK function. The way to calculate the exact age with function INTCK is

 

intck("YEAR", birth, date, "CONTINUOUS");
PG
FreelanceReinh
Jade | Level 19

Note that the three methods suggested yield different results if DOB was a February 29 and DATE is a February 28:

data _null_;
dob='29FEB2000'd;
do date='28FEB2004'd, '28FEB2005'd;
  agemc=%age(date, dob);
  ageyd=floor(yrdif(dob, date, 'age'));
  ageic=intck('year', dob, date, 'c');
  put (d:)(=date9.) (a:)(=);
end;
run;
dob=29FEB2000 date=28FEB2004 agemc=3 ageyd=4 ageic=3
dob=29FEB2000 date=28FEB2005 agemc=4 ageyd=5 ageic=5

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 2729 views
  • 1 like
  • 4 in conversation