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

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 ID pulse rate Blood Pressure pt013085 60 111 pt013086 58 121 pt013083 63 99 pt013080 62 109 pt013089 67 143 pt013088 65 119 pt013087 75 112 pt013081 70 117 pt013082 74 139 pt013084 73 151 pt013015 90 198 pt013025 102 87 pt013035 50 123 pt013045 110 165 pt013555 40 145 pt123456 67 99
Super User
Posts: 23,677

## 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: 23,677

## 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: 23,677

## 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.

Posts: 5,521

## 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
Discussion stats
• 7 replies
• 324 views
• 0 likes
• 3 in conversation