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
- /
- SAS Programming
- /
- SAS Procedures
- /
- Harmonic Mean

Topic Options

- 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
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

04-09-2008 02:20 PM

For the first time in my career, I have a need to calculate a harmonic mean across a large number of observations (harmean function is out and impractical).

I was completely surprised that proc means does not provide an option for harmonic and geometric means.

Is there a proc that has these alternate means available?

I was completely surprised that proc means does not provide an option for harmonic and geometric means.

Is there a proc that has these alternate means available?

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

Posted in reply to deleted_user

04-09-2008 04:00 PM

For Harmonic anyways why not:

Just augment your table with reciprocals then take the reciprocal of the reported mean from PROC MEANS?

Ike Eisenhauer

Just augment your table with reciprocals then take the reciprocal of the reported mean from PROC MEANS?

Ike Eisenhauer

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

Posted in reply to deleted_user

04-10-2008 09:32 AM

Chuck

I assume you have many variables and many observations to process. So transposing the data and using the SAS function HARMEAN would be impractical. Imagine transposing a data set with millions of rows!.

This isn't the most elegant solution but it gets the job done. With a little work I am confident that you can come up with an elegant solution for you specific problem.

I tried to mimic the harmean function in SAS. In the SAS documentation if any value is negative then the result is missing. And missing values need to be ignored.

data one;

input x;

datalines;

.

4

12

24

;

run;

data two;

set one end=eof;

if x <0 and not missing(X) then negative_flag+1;

x1=1/x;

cum_x+x1;

n+1;

if missing(x) then n=n-1;

if eof and not negative_flag then do;

x_harmonic_mean=1/(cum_x/n);

put x_harmonic_mean;

end;

run;

data _null_;

x2=harmean(.,4,12,24);

put x2=;

run;

-Darryl

I assume you have many variables and many observations to process. So transposing the data and using the SAS function HARMEAN would be impractical. Imagine transposing a data set with millions of rows!.

This isn't the most elegant solution but it gets the job done. With a little work I am confident that you can come up with an elegant solution for you specific problem.

I tried to mimic the harmean function in SAS. In the SAS documentation if any value is negative then the result is missing. And missing values need to be ignored.

data one;

input x;

datalines;

.

4

12

24

;

run;

data two;

set one end=eof;

if x <0 and not missing(X) then negative_flag+1;

x1=1/x;

cum_x+x1;

n+1;

if missing(x) then n=n-1;

if eof and not negative_flag then do;

x_harmonic_mean=1/(cum_x/n);

put x_harmonic_mean;

end;

run;

data _null_;

x2=harmean(.,4,12,24);

put x2=;

run;

-Darryl