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.
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
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
The syntax is
age = YRDIF(birthDate, refDate, "AGE");
where refDate can be Today() if that is what you want.
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
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
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 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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.