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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 708 views
  • 0 likes
  • 3 in conversation