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
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.
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?
I need the difference between these two dates and then the average.
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.
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.
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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.