🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Quartz | Level 8

## Re: need to calculate age for people born before 1960

Given the age of the population in the dataset I working with. I am thinking it is 1922. I'm still getting negative value after setting the yearcutoff value to 1910. Not sure what else is going on.

Ammonite | Level 13

## Re: need to calculate age for people born before 1960

set your options like this global.

options yearcutoff=1910;

Quartz | Level 8

## Re: need to calculate age for people born before 1960

options yearcutoff=1910;

data B;
set A;
b_date=datepart(birthdate);
format b_date date.;

date=today();
Age_exact = floor((intck('month',b_date,Date)-(day(Date) < day(b_date))) / 12);
format date date9.;

run;

Still getting negative age

PROC Star

## Re: need to calculate age for people born before 1960

I think you should post the FULL datetime of the birthdate variable so we know exactly what we are starting with. Also there are easier ways of getting age:

``````data B;
set A;
b_date=datepart(birthdate);
format b_date date9.
birthdate datetime24.;
date=today();
Age_exact = floor((intck('month',b_date,Date)-(day(Date) < day(b_date))) / 12);Age_Exact2 = intck('YEAR', b_date, date, 'C');
format date date9.;
put _all_;
run;``````

Super User

## Re: need to calculate age for people born before 1960

What happens when you use a DATE9 format and display the value, before the calculation?

What was your source data? It's possible you read it wrong, but its just as possible you have bad data.

options yearcutoff=1910;

data B;
set A;
b_date=datepart(birthdate);
format b_date date.;

date=today();
Age_exact = floor((intck('month',b_date,Date)-(day(Date) < day(b_date))) / 12);
format date date9.;

run;

Still getting negative age

Super User

## Re: need to calculate age for people born before 1960

The YEARCUTOFF option only impacts how SAS determine the century when converting text with two digit years into dates.

You are not converting any text into dates.  You already have data with the wrong century.

You might add logic to check the date for reasonableness before calculating age.

``````data B;
set A;
b_date=datepart(birthdate);
date=today();
if b_date > date then do;
put b_date = @ ;
b_date=intnx('year',b_date,-100,'s');
put '-> ' b_date ;
end;
current_age=int(yrdif(b_date, date, 'ACTUAL'));
format b_date date date9.;
run;``````
Quartz | Level 8

## Re: need to calculate age for people born before 1960

Thank you so much! This worked like a charm!

Super User

## Re: need to calculate age for people born before 1960

How do you know that's right though and it shouldn't be 2012, not 2022 or 1922?

One record is likely not a huge deal either way, but something to consider.

Super User

## Re: need to calculate age for people born before 1960

I tried to calculate age using the

current_age=int(yrdif(b_date, today(), 'ACTUAL')); Since the age is before 1960 for bene_id 02, It is giving me negative value.

Here is my data after calculating age:

bene_id    b_date           Current_age

01             18May64        54

02             18Jun22         -3

03              08sep51        67

Any help appreciated!

It's got nothing to do with 1960, but with the use of a 2-digit year. After the experiences of the 2000 scare, this is nothing short of stupid, stupid, stupid.

Discussion stats
• 23 replies
• 2134 views
• 8 likes
• 9 in conversation