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

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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