turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- BI
- /
- Visual Analytics
- /
- How to calculate age from birthdate using SAS VA

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-31-2015 05:46 PM - edited 10-31-2015 05:50 PM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ksulistyo

10-31-2015 11:19 PM

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

All Replies

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ksulistyo

10-31-2015 10:18 PM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ksulistyo

10-31-2015 11:07 PM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ksulistyo

10-31-2015 11:19 PM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to MichelleHomes

11-01-2015 01:49 AM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ksulistyo

05-30-2016 01:31 AM - edited 05-30-2016 01:34 AM

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) )

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