Fluorite | Level 6

FINDING MEDIAN FOR CATEGORIES OF SUBPOPULATIONS

hello here. I have the attached data set below from a National Health survey. Q indicates Quartiles that I created separately for women and men using the following code.

``````Data Project1.DII_Q;
set  Project1.DII_F;
if sex=1 and Adj_DII <=-0.382609 then Q=1;
if sex=1 and -0.382609 LT Adj_DII LE 0.618524 then Q=2;
if sex=1 and 0.618524LT Adj_DII LE 1.651765 then Q=3;
if sex=1 and Adj_DII> 1.651765 then Q=4;
if sex=2 and Adj_DII <=-0.486805 then Q=1;
if sex=2 and -0.486805 LT Adj_DII LE 0.598508 then Q=2;
if sex=2 and 0.598508 LT Adj_DII LE 1.533177 then Q=3;
if sex=2 and Adj_DII>1.533177 then Q=4;
run;``````

Now I want to assign the median of the variable Adj_DII (in the attached data set) in each quartile category to individuals in that category separately by sex.But first,   I want to find the median of Adj_DII in Q1, Q2, Q3, Q4  separately for men and women. I tried to use Proc survey means but didnt work. I need something like this;

For sex=1

median of Q1

median of Q2

median of Q3

median of Q4

And like wise for sex=2.

I tried to use Proc survey means but didnt work.

``````Proc surveymeans data=Project1.DII_Q  median;
strata kstrata;
cluster psu;
weight pooled_wt;
Domain Q;
run;``````

1 ACCEPTED SOLUTION

Accepted Solutions
SAS Employee

Re: FINDING MEDIAN FOR CATEGORIES OF SUBPOPULATIONS

You can use this syntax in PROC SURVEYMEANS to compute the medians for each sex within each category:

Domain Q*sex;

6 REPLIES 6
Obsidian | Level 7

Re: FINDING MEDIAN FOR CATEGORIES OF SUBPOPULATIONS

Hello,

You should try this code:

``````proc report data=dii_m out=dii_median;
define sex / group "Sexe";
define Q / group "Quartile";
run;``````
Fluorite | Level 6

Re: FINDING MEDIAN FOR CATEGORIES OF SUBPOPULATIONS

This is excellent and very simple.

Diamond | Level 26

Re: FINDING MEDIAN FOR CATEGORIES OF SUBPOPULATIONS

PROC SUMMARY is the tool

UNTESTED CODE

``````proc summary data=project1.dii_q nway;
class sex q;
output out=_stats_ median=;
run;``````

By the way, the median of quartiles is an "octile", or a 12.5 percentile, and so there was no need for you to compute an intermediate step of computing quartile limits and then type the limits of the quartiles into a SAS data step, as you have done.

``````proc univariate data=project1.dii_1 noprint;
class sex q;
output out=_stats_ pctlpts=12.5 37.5 62.5 87.5 pctlpre=oct;
run;``````

--
Paige Miller
SAS Employee

Re: FINDING MEDIAN FOR CATEGORIES OF SUBPOPULATIONS

You can use this syntax in PROC SURVEYMEANS to compute the medians for each sex within each category:

Domain Q*sex;

Fluorite | Level 6

Re: FINDING MEDIAN FOR CATEGORIES OF SUBPOPULATIONS

Hello. Thank you for the assistance. I think I didnt write it correctly. What I meant is that I already categorised data into Q1-Q4. I need to find the median of the variable Adj_DII in each of the Qs stratified by sex.

Fluorite | Level 6

Re: FINDING MEDIAN FOR CATEGORIES OF SUBPOPULATIONS

Thank you. Proc summary produced the results I wanted.

Thank you all for your effort.

Discussion stats
• 6 replies
• 892 views
• 4 likes
• 4 in conversation