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

Hi,

 

When trying to calculate the age using death and birth dates, leaves output as 50.7677488 etc. However, displaying  values like this 51 is expected instead of 50.7677488.

data data1_;
	attrib BRTHDAT_ DTHDAT_  length=8 format=date9.;
	attrib AGE_D length=3;
	set data1;

if BRTHDAT ne . then
	BRTHDAT_=datepart(BRTHDAT);

if DTHDAT ne . then
	DTHDAT_=datepart(DTHDAT);

if DTHDAT_ ne . and BRTHDAT_ ne . then do;
	AGE_D=(DTHDAT_ - BRTHDAT_)/365.25;
end;

proc sort data=data1_;
	by SUBJECT;
run;

Attached is the code.

Any correction that has to be made to display the age right?

Thank you,

 

Regards,

Nasya

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

I imagine you are looking for the age to be rounded:

 


if DTHDAT_ ne . and BRTHDAT_ ne . then do;
AGE_D= round((DTHDAT_ - BRTHDAT_)/365.25);
end;

 

Alternatively, leave the calculations as they are, but change the attributes of AGE_D:


attrib AGE_D length=8 format=3.;

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

can ceil function help?

 

if DTHDAT_ ne . and BRTHDAT_ ne . then do;
	AGE_D=ceil((DTHDAT_ - BRTHDAT_)/365.25);

 

or using yrdif and ceil

 

   age=ceil(yrdif(brthdat_, dthdat_, 'AGE'));

 

Nasya
Obsidian | Level 7
using yrdif and ceil worked..
Thank you,

NASYA
Astounding
PROC Star

I imagine you are looking for the age to be rounded:

 


if DTHDAT_ ne . and BRTHDAT_ ne . then do;
AGE_D= round((DTHDAT_ - BRTHDAT_)/365.25);
end;

 

Alternatively, leave the calculations as they are, but change the attributes of AGE_D:


attrib AGE_D length=8 format=3.;

Nasya
Obsidian | Level 7
Yes, thats correct
Nasya
Obsidian | Level 7
Worked. Thank you.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2243 views
  • 0 likes
  • 3 in conversation