DATA Step, Macro, Functions and more

calculate date someone turned a certain age

Accepted Solution Solved
Reply
Super Contributor
Posts: 279
Accepted Solution

calculate date someone turned a certain age

I need to calculate when this person turned 6 and then count the the number of days from the servedate to the date he turned six, essentially TurnedSix-Servedate (expressed in days)

 

data temp;
infile datalines dsd missover;
informat dob servedate mmddyy8.;
input dob servedate;
cards;
10/20/10, 01/20/16
;
run;
proc print;
format dob servedate mmddyy.;
run;
data need;
set temp;
TurnedSix= ;
DaysServed= ;
run;


Accepted Solutions
Solution
‎06-20-2017 04:10 PM
Super User
Posts: 19,861

Re: calculate date someone turned a certain age

Use INTNX to increment the birthdate 6 years.

 

date_6years = intnx('year', dob, 6, 's');

date_diff = servedate - date_6years;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,932

Re: calculate date someone turned a certain age

[ Edited ]

Date person turns 6 can be computed with the INTNX function, or just by incrementing the year by 6.

 

Since the variables of interest are already SAS date values (am I correct about this?), all you have to do is do the subtraction and you will know the number of days. You could also use INTNX, but subtraction is simpler.

Solution
‎06-20-2017 04:10 PM
Super User
Posts: 19,861

Re: calculate date someone turned a certain age

Use INTNX to increment the birthdate 6 years.

 

date_6years = intnx('year', dob, 6, 's');

date_diff = servedate - date_6years;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 236 views
  • 0 likes
  • 3 in conversation