Hi,
Ok, I have been multiplying the dates from 1960 forward using 365.25*Years etc. But there has to be an easier way. The today() is useful, but what about for other dates? Also, even the today gives me the proper year, but the age is one year too high because it calculates the year as 1/1. So, someone born on March 1st 1990 would be calculated as being 28 on Jan 1 2018, even though they are still 27.
Below is code. I am very busy learning SAS and this is a minor annoyance that will help me speed things up. Thanks. Placing "Age" in the third field of Intck appears to be one option, but are there others?
Libname Review'/folders/myfolders/Review' ; Libname Learn'/folders/myfolders/Learn' ; Libname myformat'/folders/myfolders/sasuser.v94' ; Options fmtsearch=(myformat) ; Data review.Prob9_4 ; Set Learn.Hosp ; AgeJan1 = Intck('Year',DOB, 01/01/2006) ; AgeToday = Intck('Year',DOB, today()) ; /*Need to calculate SAS Date*/ format DOB Date9. AgeJan1 AgeToday 3. ; run ; Proc print data=review.Prob9_4 noobs ; run ;
Ok, so INTCK really looks at the interval, regardless of date month, so Yrdif is probably better. Also, even then, using the int function before Yrdif is needed to get the correct age. The code below works best. Thanks.
Data review.Prob9_4 ; Set Learn.Hosp ; AgeJan1 = int(YrDif(DOB, '01Jan2006'd, 'Actual')) ; AgeToday = int(YrDif(DOB, '19Apr2018'd,'Actual')) ; /*Need ot calculate SAS Date*/ format DOB Date9. AgeJan1 AgeToday 3. ; run ;
Ok, so INTCK really looks at the interval, regardless of date month, so Yrdif is probably better. Also, even then, using the int function before Yrdif is needed to get the correct age. The code below works best. Thanks.
Data review.Prob9_4 ; Set Learn.Hosp ; AgeJan1 = int(YrDif(DOB, '01Jan2006'd, 'Actual')) ; AgeToday = int(YrDif(DOB, '19Apr2018'd,'Actual')) ; /*Need ot calculate SAS Date*/ format DOB Date9. AgeJan1 AgeToday 3. ; 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.