BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
3 REPLIES 3
Ksharp
Super User
[pre]
mediandate = mean(startdate,enddate);
format mediandate mmddyy8.;
[/pre]


Ksharp
Cynthia_sas
SAS Super FREQ
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
deleted_user
Not applicable
Thanks Ksharp!! It does the trick.

sas-innovate-2024.png

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.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 6156 views
  • 0 likes
  • 3 in conversation