BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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?
2 REPLIES 2
deleted_user
Not applicable
For Harmonic anyways why not:

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

Ike Eisenhauer
darrylovia
Quartz | Level 8
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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 1864 views
  • 0 likes
  • 2 in conversation