How to find the median (without use of median function) and export to excel?

Reply
Occasional Contributor
Posts: 8

How to find the median (without use of median function) and export to excel?

Not completely sure how to use the 'retain' and/or 'sum' statements or if they even apply.

patient IDpulse rateBlood Pressure
pt01308560111
pt01308658121
pt0130836399
pt01308062109
pt01308967143
pt01308865119
pt01308775112
pt01308170117
pt01308274139
pt01308473151
pt01301590198
pt01302510287
pt01303550123
pt013045110165
pt01355540145
pt1234566799
Super User
Posts: 17,819

Re: How to find the median (without use of median function) and export to excel?

proc means with median.

Occasional Contributor
Posts: 8

Re: How to find the median (without use of median function) and export to excel?

Thanks man. I know the proc means with the median option but I wanted help on trying to figure it out

with the use of retain and sum statements in other words through the use of 'brute force'.

I appreciate any help

Super User
Posts: 17,819

Re: How to find the median (without use of median function) and export to excel?

You need to define what's a median to you, specifically if you have even number of observations.

Sum is not required to calculate median, retain/lag may or may not be helpful depending on your methodology.

You do need to sort your data set first, find the number of obs. If odd, take the middle value, you can use point in a data step.

If even then it depends on your method, usually an average, so then two point statements in a datastep would work.

Occasional Contributor
Posts: 8

Re: How to find the median (without use of median function) and export to excel?

I forgot to mention that the median would be for the Blood pressure variable and to be saved in another variable median_1 in excel I'm trying to apply your comments but I'm going nuts.

Thanks again

Super User
Posts: 17,819

Re: How to find the median (without use of median function) and export to excel?

Explain why you can't use proc means or standard procs. Otherwise it sounds like homework, which I don't feel inclined to help with.

Occasional Contributor
Posts: 8

Re: How to find the median (without use of median function) and export to excel?

Competition between coworkers where one claims to be able to find the median without using standard (faster/more comprehensive) methods like proc means, univariate, etc.

Respected Advisor
Posts: 4,646

Re: How to find the median (without use of median function) and export to excel?

This is quite simple. Consider the ingredients:

NOBS option to SET statement

_N_ automatic variable

and answer the question : Where do you expect the median value to be in a sorted dataset?

PG

PG
Ask a Question
Discussion stats
  • 7 replies
  • 294 views
  • 0 likes
  • 3 in conversation