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

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Averaging the values of two variables

- 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-01-2008 10:15 PM

We would like to create a new variable that is the average of two variables measuring time.

We are trying to find the average of the maximum number of days spent in a program and the minimum number of days. We tried this code:

avg=mean(min_days, max_days)

But it does not work. Is there a simple formula that sas will understand to create an average like this?

Thank you

We are trying to find the average of the maximum number of days spent in a program and the minimum number of days. We tried this code:

avg=mean(min_days, max_days)

But it does not work. Is there a simple formula that sas will understand to create an average like this?

Thank you

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

06-02-2008 09:27 AM

Caitlin,

The syntax is correct (except for the missing semi-colon). The mean function, used in a data step, requires that both the values are present for each observation to get a non-missing result.

I wonder if you are really asking a different question, and looking for the mid-range ( http://en.wikipedia.org/wiki/Midrange ) of all observations in a set?

If so, you may need to attack it differently:

1) PROC MEANS to output the min and max.

2) DATA step on the output to get the mid-range.

Doc

The syntax is correct (except for the missing semi-colon). The mean function, used in a data step, requires that both the values are present for each observation to get a non-missing result.

I wonder if you are really asking a different question, and looking for the mid-range ( http://en.wikipedia.org/wiki/Midrange ) of all observations in a set?

If so, you may need to attack it differently:

1) PROC MEANS to output the min and max.

2) DATA step on the output to get the mid-range.

Doc

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

06-05-2008 12:56 AM

Based on your code, you want something that looks like this.

Name min_days max_days avg

John 5 10 7.5

Joan 1 14 7.5

Pat 5 16 10.5

What is happening when you run your code because that code looks correct?

If the midrange across all data is what you want, try this:

proc sql;

select mean(min(min_days),Max(max_days)) from work.data;

It will give you the single mean of 8.5 between just 1 and 16.

Name min_days max_days avg

John 5 10 7.5

Joan 1 14 7.5

Pat 5 16 10.5

What is happening when you run your code because that code looks correct?

If the midrange across all data is what you want, try this:

proc sql;

select mean(min(min_days),Max(max_days)) from work.data;

It will give you the single mean of 8.5 between just 1 and 16.