New Contributor
Posts: 4

# How do I calculate median values across same observation but different variables?

[ Edited ]

Hello,

I am using SAS 9.3. I have this dataset here, and I want to calculate the median of all the intervals across the same observation, for all observations.

I have attached the sample dataset (in Excel format) that I am referring to.

I want to code a new variable/column that has the calculated median interval for each observation based on any interval values that that observation has. How can I do that?

Thank you very much!

Super User
Posts: 13,583

## Re: How do I calculate median values across same observation but different variables?

No attachement.

If you have a SAS dataset then best is to post a datastep to duplicate your data. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

You can add a median for selected variables similar to this:

```data want;
set have;
MedianValue = median(var1, var2, var3, var4);
run;```

Replace var1, var2 etc with your list of variables you are interested in.

Or a valid variable list.

Super User
Posts: 23,776

## Re: How do I calculate median values across same observation but different variables?

Remember to show both what you have AND what you want.

Preferably directly in the post rather than an attachment.

Two ways to calculate median - using the function as shown

or Proc Means

PROC Star
Posts: 8,167

## Re: How do I calculate median values across same observation but different variables?

For your data you could simplify the code to:

```data want;
set have;;
Median = median(of int:);
run;
```

Art, CEO, AnalystFinder.com

Discussion stats
• 3 replies
• 365 views
• 0 likes
• 4 in conversation