Programming the statistical procedures from SAS

Median date between two dates

Reply
N/A
Posts: 0

Median date between two dates

Hi,

I have two variables: startdate and endate.

Is there a way to create a new variable called "mediandate" to find the median between the startdate and enddate?

So for example,

StartDate EndDate MedianDate
6/1/10 7/1/10 6/16/10

If there is an easier way of doing it without having to do it by hand, that would be great! Any help would be appreciated...

-Pauline
Super User
Posts: 9,775

Re: Median date between two dates

[pre]
mediandate = mean(startdate,enddate);
format mediandate mmddyy8.;
[/pre]


Ksharp
SAS Super FREQ
Posts: 8,781

Re: Median date between two dates

Hi:
The definition of MEAN and MEDIAN can be found on this page:
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#/documentation/cdl/en...
quote
Mean:
The most commonly used parameter is the (arithmetic) mean. If the population contains a finite number of values, then the population mean is computed as the sum of all the values in the population divided by the number of elements in the population. For an infinite population, the concept of the mean is similar but requires more complicated mathematics.

Median:
The population median is the central value, lying above and below half of the population values. The sample median is the middle value when the data are arranged in ascending or descending order. For an even number of observations, the midpoint between the two middle values is usually reported as the median.
endquote


In some data circumstances, the MEAN and MEDIAN would result in the same number, however, it is possible for you to get two different numbers from these statistics.

For example, in SASHELP.SHOES, you might want to compare the MEAN of all SALES with the MEDIAN of all SALES. In this instance, we would use PROC MEANS:
[pre]
proc means data=sashelp.shoes n mean median;
var sales;
run;

[/pre]

and the results are:
[pre]
Analysis Variable : Sales Total Sales

N Mean Median
-----------------------------------
395 85700.17 38912.00
-----------------------------------
[/pre]

which is very different.

Of course these numbers are calculated across a whole dataset. For rowwise or observation-wise calculations, there are the MEAN and MEDIAN functions, which are documented here:
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#/documentation/cdl/...
and
http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#/documentation/cdl/...

Once you understand exactly what you want to do, then you will know which is the right function or procedure to use.

cynthia
N/A
Posts: 0

Re: Median date between two dates

Thanks Ksharp!! It does the trick.
Ask a Question
Discussion stats
  • 3 replies
  • 1542 views
  • 0 likes
  • 3 in conversation