BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Zacc
Fluorite | Level 6

 

First, I do have a variable, year of birth (i.e. without days and months of births). Second, I would like to derive age from the stated variable based on today’s date. I’ve attempted the derivation using the following code but I’ve been unsuccessful.

 

Data myage;
set suvdata;
AGE=floor(YRDIF(RB080, today(),"AGE"));
run;

I shall be most grateful for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

The YRDIF function want two date values. So use the MDY function to create date

 

AGE=floor(YRDIF(mdy(1,1,RB080), today(),"AGE"));

would use January 1 as the date in the year.

View solution in original post

3 REPLIES 3
ballardw
Super User

The YRDIF function want two date values. So use the MDY function to create date

 

AGE=floor(YRDIF(mdy(1,1,RB080), today(),"AGE"));

would use January 1 as the date in the year.

Zacc
Fluorite | Level 6

@ballardw, Thank you so very much.

PaigeMiller
Diamond | Level 26

@Zacc wrote:

 

First, I do have a variable, year of birth (i.e. without days and months of births).


So in other words, you just have the year of birth, is that what you are saying? The value of your variable might look like 1978.

 

So you would compute the age via

 

data want;
set have;
age = 2022 - rb080;
run;
--
Paige Miller

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

LIBNAME 101

Follow along as SAS technical trainer Dominique Weatherspoon expertly answers all your questions about SAS Libraries.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 834 views
  • 0 likes
  • 3 in conversation