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

Hi, 
I am attempting to calculate the age of individuals in my data set using their date of birth and the date their clinical treatment started.  Following that I will be attempting to create age groups according to their age at their addmitance.

 

Please note that this data is over a period of time, and individuals can have been admitted on multiple occasions.

 

An example of the data:

 

clientid           dob              clstartdate

123                10435           18309

122                3982             19452

156               -13125           20065

189                11497           17875

192                10977           19912

 201               3133              20391

 

How would I go about calculating their age? 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Use the intck() function:

data have;
input clientid dob clstartdate;
cards;
123 10435 18309
122 3982 19452
156 -13125 20065
189 11497 17875
192 10977 19912
201 3133 20391
;
run;

data want;
set have;
age_at_clt = intck('year',dob,clstartdate);
run;

Or you could use a basic calculation:

age_at_clt = (clstartdate - dob) / 365.25;

Or, for special types of "age":

age_at_clt = year(clstartdate) - year(dob);

So it's up to you to define what "age" is supposed to be in your context.

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

Use the intck() function:

data have;
input clientid dob clstartdate;
cards;
123 10435 18309
122 3982 19452
156 -13125 20065
189 11497 17875
192 10977 19912
201 3133 20391
;
run;

data want;
set have;
age_at_clt = intck('year',dob,clstartdate);
run;

Or you could use a basic calculation:

age_at_clt = (clstartdate - dob) / 365.25;

Or, for special types of "age":

age_at_clt = year(clstartdate) - year(dob);

So it's up to you to define what "age" is supposed to be in your context.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Those calculations you give Kurt, are they accurate, I know the 365.25 is just an approximation, but how about the others?  I know for a long time we used:

int((intck('month',<birth>,<start>)-(day(<birth>)> day(<start>))) /12)

To get the most accurate age reading, but maybe the functions like year now cover this?

Kurt_Bremser
Super User

Those three calculations were just the proverbial "tip of the iceberg".

There are so many ways to go about it, and so much more ways to fine-tune those, that it will be up to the developer to determine which one to use in the end.

It comes down to try those methods and compare their results with the desired outcome, over a sufficient lot of test cases. Just defining the test cases can be a major challenge (and is often the most important part of developing, I'm a big supporter of test-driven development).

 

The 365.25 approximation should work reasonably well for timespans in the range of lifetimes. It depends if a "legal" age value is needed, or a value best suited for statistics.

Ksharp
Super User

I would like to use 

 

age_at_clt = yrdif(dob,clstartdate,'age');

 

senac255
Fluorite | Level 6
The intck expression did the trick.
Thanks!

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 968 views
  • 3 likes
  • 4 in conversation