BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
NewUsrStat
Lapis Lazuli | Level 10

Hi guys, 

suppose to have the following median age (Q1-Q3) by hospitals from a demographic table: 

 

Hospital A             Hospital B            Hospital C

43(39-61)             55(41-78)             57(43-59)

 

How can I put the median overall with Q1-Q3 without calculating that on the entire cohort from data? 

I have not the original data but only the final table. 

 

Edit: what I would like to do is to give a single number (median and Q1-Q3) that represents all the Hospitals

 

Thank you in advance

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

You can't. That operation is not mathematically feasible. Because of the way the median is computed, you cannot estimate the overall median from the medians of the groups. For example, the following two data sets have exactly the same medians across all classes, but different overall medians. 

 

data A;
input Group $ Value;
datalines;
A 1
A 2
A 3
B 2
B 4
B 6
;
proc means data=A median printalltypes ;
   class Group;
   var Value;
run;


data B;
input Group $ Value;
datalines;
A 1
A 2
A 3
B 4
B 4
B 6
;
proc means data=B median printalltypes ;
   class Group;
   var Value;
run;

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

@NewUsrStat wrote:

 

How can I put the median overall with Q1-Q3 without calculating that on the entire cohort from data? 

I have not the original data but only the final table. 


I really don't understand what you are saying, please describe in more detail.

--
Paige Miller
Rick_SAS
SAS Super FREQ

You can't. That operation is not mathematically feasible. Because of the way the median is computed, you cannot estimate the overall median from the medians of the groups. For example, the following two data sets have exactly the same medians across all classes, but different overall medians. 

 

data A;
input Group $ Value;
datalines;
A 1
A 2
A 3
B 2
B 4
B 6
;
proc means data=A median printalltypes ;
   class Group;
   var Value;
run;


data B;
input Group $ Value;
datalines;
A 1
A 2
A 3
B 4
B 4
B 6
;
proc means data=B median printalltypes ;
   class Group;
   var Value;
run;
NewUsrStat
Lapis Lazuli | Level 10
Thank you very much! Maybe the mean of the means is feasible?
Rick_SAS
SAS Super FREQ

You can do the mean of means if you know the number observations in each group.

Assume

  • The first group has N1 observations and the mean is M1
  • The second group has N2 observations and the mean is M2
  • The third group has N3 observations and the mean is M3 

Then the overall mean is 

(N1*M1 + N2*M2 + N3*M3) /  (N1 + N2 + N3)

 

The numerator is the sum of the variable. The denominator is the total number of observations.

FreelanceReinh
Jade | Level 19

Hi @NewUsrStat,

 

I think what you can say in general about the overall quartiles Q1, Q2 (median) and Q3 is that they are in the range of the corresponding group-specific quartiles:

39 <= Q1 <= 43
43 <= Q2 <= 57
59 <= Q3 <= 78

(assuming QNTLDEF=5 and that the given group-specific quartiles are exact).

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand in the Innovate Hub.

Watch Now →
What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 3034 views
  • 5 likes
  • 4 in conversation