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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
MichelleHomes
Meteorite | Level 14

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

//Contact me to learn how Metacoda software can help keep your SAS platform secure - https://www.metacoda.com

View solution in original post

5 REPLIES 5
kannand
Lapis Lazuli | Level 10

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
PGStats
Opal | Level 21

The syntax is 

 

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

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

PG
MichelleHomes
Meteorite | Level 14

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

//Contact me to learn how Metacoda software can help keep your SAS platform secure - https://www.metacoda.com
ksulistyo
SAS Employee

 

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
Expengu
SAS Employee

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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Tips for filtering data sources in SAS Visual Analytics

See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 7380 views
  • 6 likes
  • 5 in conversation