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

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.

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

set your options like this global.

 

options yearcutoff=1910;

pmpradhan
Quartz | Level 8

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

SASKiwi
PROC Star

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;

 

Reeza
Super User

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.

 


@pmpradhan wrote:

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


 

Tom
Super User Tom
Super User

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;
pmpradhan
Quartz | Level 8

Thank you so much! This worked like a charm!

Reeza
Super User

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.

Kurt_Bremser
Super User

@pmpradhan wrote:

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.

SAS Innovate 2025: Register Now

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!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

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