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.
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.
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.
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;
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!
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.