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

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 ; 
1 ACCEPTED SOLUTION

Accepted Solutions
ManitobaMoose
Quartz | Level 8

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 ; 

View solution in original post

3 REPLIES 3
Reeza
Super User
INTNX? What are you trying to do, calculate age?
Reeza
Super User
And lookup INTCK, the last parameter is not being used.
ManitobaMoose
Quartz | Level 8

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 ; 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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
  • 776 views
  • 0 likes
  • 2 in conversation