BookmarkSubscribeRSS Feed
hjjijkkl
Pyrite | Level 9

I have a data with variables for day month and year and i want to calculate the age of the subject.

id month day year
1 1 27 1985
2 10 12 2002
3 5 20 1990

the output will look like this 

id Calculated age 
1 36
2 18
3 30
2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Try this

 

data have;
input id month day year;
datalines;
1 1  27 1985
2 10 12 2002
3 5  20 1990
;

data want(drop = dob);
   set have;
   dob = mdy(month, day, year);
   age = int(yrdif(dob, today(), 'act/act'));
run;

 

Result:

 

id  month  day  year  age 
1   1      27   1985  36 
2   10     12   2002  18 
3   5      20   1990  30 
ballardw
Super User

Age requires TWO date values. Which specific date is the shown month, day and year to be compared with?

 

It is also always a good idea to indicate what units something like age is reported in. I deal with data where age in different sets is days, weeks, months, occasionally weeks and months,   and years depending on the subject of the report.

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 531 views
  • 0 likes
  • 3 in conversation