DATA Step, Macro, Functions and more

Average between two date column

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 19
Accepted Solution

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.

 

Thanks in advance.

Vishyy


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

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.

View solution in original post


All Replies
Super User
Posts: 11,343

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: 11,343

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: 19,772

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: 5,498

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.

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

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