Help using Base SAS procedures

Averaging the values of two variables

Reply
N/A
Posts: 0

Averaging the values of two variables

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
Trusted Advisor
Posts: 2,113

Re: Averaging the values of two variables

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
Contributor
Posts: 35

Re: Averaging the values of two variables

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.
Ask a Question
Discussion stats
  • 2 replies
  • 131 views
  • 0 likes
  • 3 in conversation