Help using Base SAS procedures

Subtraction between 2 different date formats

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

Subtraction between 2 different date formats

I am dealing with a situation where I have 2 different date formats. One is a full date formatted as yymmdd8. The other is just a year formatted as BEST12. I need to do a subtraction to calculate age at the event and select cases higher than a certain age. Please advise a solution.


Accepted Solutions
Solution
‎11-18-2014 12:18 AM
Super User
Super User
Posts: 6,498

Re: Subtraction between 2 different date formats

You just need to define what your algorithm is for defining age at event.  The simplest is to just use the year from the event.

age_at_event = year(event_date) - year_of_birth ;

View solution in original post


All Replies
Respected Advisor
Posts: 4,641

Re: Subtraction between 2 different date formats

One way is to transform YEAR into a SAS date, say the first of April of that year with MDY(4, 1, YEAR) and then use function YRDIF to calculate the age. Assuming DATE is greater than MDY(4, 1, YEAR) :

if yrdif( mdy(4, 1, year), date, "AGE" ) > ageLimit;

PG

PG
Solution
‎11-18-2014 12:18 AM
Super User
Super User
Posts: 6,498

Re: Subtraction between 2 different date formats

You just need to define what your algorithm is for defining age at event.  The simplest is to just use the year from the event.

age_at_event = year(event_date) - year_of_birth ;

Occasional Contributor
Posts: 13

Re: Subtraction between 2 different date formats

Tom,

This was very helpful and it solved the problem. Thank you for your time. I really appreciate the help.

Sanket

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 202 views
  • 0 likes
  • 3 in conversation