BookmarkSubscribeRSS Feed
Smitha9
Fluorite | Level 6

Hi,

I am using this code for pulling the birthdate >17years

FLOOR(intck('MONTH',datepart(pt.BIRTH_DATE), date())/12)> 17

 

But the person who has DOB of 06/29/2006 is considered as 18years and pulling that person. i tried not to use FLOOR and it still gives me the same 18years.

 

Can I fix this.

3 REPLIES 3
s_lassen
Meteorite | Level 14

It's probably easier to use the YRDIF function:

yrdif(datepart(pt.BIRTH_DATE),date(),'AGE')>=18

- I think that should give the answer you want.

 

ballardw
Super User

Are you sure that your PT.BIRTH_DATE is a date time value? If the a variable is actually a date value then the DATEPART function is likely returning a date in 1960.

 

data example;
   x= datepart('29JUN2006'd);
   put x= date9.;
run;

So likely every birth date in your data is generating ages > 17, mostly >60.

 

If the values are dates remove the DATEPART function call.

Tom
Super User Tom
Super User

You want to add the CONTINUOUS option to the INTCK() function count. Otherwise it is counting when you cross the BEGINNING of the month.

data test;
  birth_date = '29JUN2006'd;
  birth_dt   = '29JUN2006:00:00'dt;
  format birth_date date9. birth_dt datetime18.;
  age = yrdif(BIRTH_DATE,date(),'AGE') ;
  yr1 = floor(intck('month',birth_date,date(),'c')/12);
  yr2 = floor(intck('month',datepart(birth_dt),date(),'c')/12);
  yr3 = floor(intck('month',datepart(birth_date),date(),'c')/12);
run;

Tom_0-1718653818155.png

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1813 views
  • 2 likes
  • 4 in conversation