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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

5 REPLIES 5
ballardw
Super User

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?

vishyy
Obsidian | Level 7

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

ballardw
Super User

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.

Reeza
Super User

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. 

Astounding
PROC Star

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 3552 views
  • 1 like
  • 4 in conversation