BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
2 REPLIES 2
Doc_Duke
Rhodochrosite | Level 12
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
rab24
Calcite | Level 5
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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2391 views
  • 0 likes
  • 3 in conversation