Exploring, predicting and reporting with SAS Visual Analytics and SAS Visual Statistics

How to calculate age from birthdate using SAS VA

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

How to calculate age from birthdate using SAS VA

[ Edited ]

Hi,

 

I'm a total noob in SAS VA. Currently using SAS VA 7.2.

Kindly advise how to calculate age from birthdate using SAS VA.

This should be simple, just substraction between today and birthdate.

I looked at the Operators in New Calculated Item, but nothing worked.

I have searched/googled this topic but what the solutions were using SAS programming or EG, but not applicable in SAS VA.

 

Thank you.


Accepted Solutions
Solution
‎11-01-2015 02:10 AM
Trusted Advisor
Posts: 1,321

Re: How to calculate age from birthdate using SAS VA

Posted in reply to ksulistyo

Welcome to the SAS Visual Analytics community.

 

As you may have discovered dates in SAS Visual Analytics are not treated the same way as Base SAS. Also the very useful Base SAS date functions such as intck and yrdif are not available.

 

A date in SAS Visual Analytics is treated as a category data item and not as the traditional SAS date type in the interface. The underlying storage is a SAS date number so you can use the Year function and DatePart function (in case your date is datetime) and you use the TreatAs function to treat the data item as a number if you want to calculate the days. Have a read through the post https://communities.sas.com/t5/SAS-Visual-Analytics/Finding-No-of-Days-between-two-dates-in-SAS-VA/m...

 

In future, please search first the community before posting a question as you may find your question has been answered already. :-)

 

Kind Regards,

Michelle

View solution in original post


All Replies
Regular Contributor
Posts: 161

Re: How to calculate age from birthdate using SAS VA

Posted in reply to ksulistyo

I'm not sure of SAS VA is different from SAS Base, but ran across this.... might help you...

 

age = INT(YRDIF(birth-date, ending-date,'ACTUAL'));

 

https://support.sas.com/publishing/authors/extras/61860_update.pdf

Kannan Deivasigamani
Respected Advisor
Posts: 4,927

Re: How to calculate age from birthdate using SAS VA

Posted in reply to ksulistyo

The syntax is 

 

age = YRDIF(birthDate, refDate, "AGE");

where refDate can be Today() if that is what you want.

PG
Solution
‎11-01-2015 02:10 AM
Trusted Advisor
Posts: 1,321

Re: How to calculate age from birthdate using SAS VA

Posted in reply to ksulistyo

Welcome to the SAS Visual Analytics community.

 

As you may have discovered dates in SAS Visual Analytics are not treated the same way as Base SAS. Also the very useful Base SAS date functions such as intck and yrdif are not available.

 

A date in SAS Visual Analytics is treated as a category data item and not as the traditional SAS date type in the interface. The underlying storage is a SAS date number so you can use the Year function and DatePart function (in case your date is datetime) and you use the TreatAs function to treat the data item as a number if you want to calculate the days. Have a read through the post https://communities.sas.com/t5/SAS-Visual-Analytics/Finding-No-of-Days-between-two-dates-in-SAS-VA/m...

 

In future, please search first the community before posting a question as you may find your question has been answered already. :-)

 

Kind Regards,

Michelle

Occasional Contributor
Posts: 8

Re: How to calculate age from birthdate using SAS VA

Posted in reply to MichelleHomes

 

Thank you for all your responses.

Unfortunately SAS VA doesn't support YRDIF.

I followed the link from Michelle with some modification and it worked :-)

Here is what I do:

    ( TreatAs(_Number_, Now()) - TreatAs(_Number_, 'Birthdate'n) ) / ( 365 * 24 * 60 * 60 )

 

Regards,

Karina


Calculating Age From Birthdate.png
SAS Employee
Posts: 2

Re: How to calculate age from birthdate using SAS VA

[ Edited ]
Posted in reply to ksulistyo

Here is a more precise calculation for age as at today:

IF ( (

  IF ( ( ( Year(DatePart(Now())) Mod 4 ) = 0 ) AND ( DayOfYear(DatePart(Now())) > 59 ) )

  RETURN ( DayOfYear(DatePart(Now())) - 1 )

  ELSE DayOfYear(DatePart(Now())) ) < (

  IF ( ( ( Year('Birth Date'n) Mod 4 ) = 0 ) AND ( DayOfYear('Birth Date'n) > 59 ) )

  RETURN ( DayOfYear('Birth Date'n) - 1 )

  ELSE DayOfYear('Birth Date'n) ) )

RETURN ( ( Year(DatePart(Now())) - Year('Birth Date'n) ) - 1 )

ELSE ( Year(DatePart(Now())) - Year('Birth Date'n) )

Age as at today.PNG

This considers the leap years, where 29th February is the 60th day of the leap year. Also replace DatePart(Now()) with a  date variable will give you the difference in year between two dates.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 2099 views
  • 3 likes
  • 5 in conversation