## Average between two date column

Solved
Occasional Contributor
Posts: 19

# Average between two date column

Hi

I have two date columns namely accept_date and issue_date.

Both are numeric and in format 08MAR2008.

I need to find average between accept_date and issue_date.

Vishyy

Accepted Solutions
Solution
‎04-08-2017 05:32 AM
Super User
Posts: 6,933

## Re: Average between two date column

One possibility:

data want;

set have;

days_between = issue_date - accept_date;   /* may need to reverse this */

run;

proc means data=want;

var days_between;

run;

Part of the answer depends on what you mean when you say "find" the average.  This program gives you a report with the average.

All Replies
Super User
Posts: 13,939

## Re: Average between two date column

You may want to clarify this a bit. The average is likely to have a fractional component. How do you want that treated?

Example:

```data _null_;
meandate = mean('01FEB2017'd,'02FEB2017'd);
put meandate  meandate= date9. ;
run;```

In terms of a format the date would get rounded.

So do you want an integer date value for the mean or what?

Occasional Contributor
Posts: 19

## Re: Average between two date column

I need the difference between these two dates and then the average.

Super User
Posts: 13,939

## Re: Average between two date column

average can be done with the mean function as in my previous example. Just put your variables in place of the values.

Difference may require more information. Is one date always after the other and you want the later minus the earlier? Of is there more of a rule involved.

difference = accept_date - issue_date;

is one way.

Super User
Posts: 24,000

## Re: Average between two date column

1. Find the difference for every record.

2. Compute the average the distance variable created from step 1.

You haven't provided any data so we can't say how this should be coded. There have been some suggestions but they're based on experience and guesses at this point.

Solution
‎04-08-2017 05:32 AM
Super User
Posts: 6,933

## Re: Average between two date column

One possibility:

data want;

set have;

days_between = issue_date - accept_date;   /* may need to reverse this */

run;

proc means data=want;

var days_between;

run;

Part of the answer depends on what you mean when you say "find" the average.  This program gives you a report with the average.

☑ This topic is solved.

Discussion stats
• 5 replies
• 285 views
• 0 likes
• 4 in conversation