Date: Wed, 4 Feb 2004 14:35:21 -0500 "DePuy, Venita" "SAS(r) Discussion" "DePuy, Venita" Re: 50th Percentile To: Bruce Johnson text/plain

Perhaps I'm just misreading this, but aren't you just looking for the median?? more specifically, to print the person with the median batting average.

But what if it's not exact? Perhaps you want the closest one. In that case, would you want to print the person whose batting average was closest? (ie if there are an even number of batters, it'd be the mean of the two middle people) A second revised bit of code follows (after the first) to account for that case. HTH Venita

data batters; input lname \$ fname \$ avg; cards; SAMMY SOSA .341 MOISES ALOU .249 PAUL BAKO .205 ALEX GONZALEZ .241 ARAMIS RAMIREZ .301 COREY PATTERSON .292 DAVID KELTON .285 ; run;ods trace off; proc univariate; var avg; ods output Quantiles=quantiles; data _null_; set quantiles; where Quantile like '50%'; call symput ('median',Estimate); run; %put Median estimate: &median;

proc print data=batters; where avg = &median; run;

/* Alternate method in case it's not exact */ data batters; input lname \$ fname \$ avg; cards; SAMMY SOSA .341 MOISES ALOU .249 ALEX GONZALEZ .241 ARAMIS RAMIREZ .301 COREY PATTERSON .292 DAVID KELTON .285 ; run;ods trace off; proc univariate; var avg; ods output Quantiles=quantiles; data _null_; set quantiles; where Quantile like '50%'; call symput ('median',Estimate); run; %put Median estimate: &median;

data batters; set batters; diff_avg = abs(avg-&median); proc sort; by diff_avg; data batters; set batters; if _N_ > 1 then delete; proc print data=batters; run; > ---------- > From: Bruce Johnson[SMTP:bjohnson@SOLUCIENT.COM] > Reply To: Bruce Johnson > Sent: Wednesday, February 04, 2004 2:22 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: 50th Percentile > > I have a project request where I have to find the 50th percentile for a > field, and then print that, along with other information on that > particular record. Let's say I have a dataset that is built from this > code: > > data batters; > input lname \$ fname \$ avg; > cards; > SAMMY SOSA .341 > MOISES ALOU .249 > PAUL BAKO .205 > ALEX GONZALEZ .241 > ARAMIS RAMIREZ .301 > COREY PATTERSON .292 > DAVID KELTON .285 > ; > run; > > Proc Univariate, from what I can tell, will not allow me to display the > LNAME and FNAME for the AVG that is the 50th percentile. How can I > report the AVG that is the 50th percentile along with the LNAME and > FNAME for that record? > > Thanks in advance. > >

Back to: Top of message | Previous page | Main SAS-L page