turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- Analytics
- /
- Stat Procs
- /
- Median date between two dates

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-14-2010 10:55 PM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-15-2010 02:09 AM

[pre]

mediandate = mean(startdate,enddate);

format mediandate mmddyy8.;

[/pre]

Ksharp

mediandate = mean(startdate,enddate);

format mediandate mmddyy8.;

[/pre]

Ksharp

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-15-2010 08:56 AM

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

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...

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.

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-15-2010 09:59 AM

Thanks Ksharp!! It does the trick.