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;
var Adj_DII;
run;
Kindly request for your assistance.
You can use this syntax in PROC SURVEYMEANS to compute the medians for each sex within each category:
Domain Q*sex;
Hello,
You should try this code:
proc report data=dii_m out=dii_median;
columns sex Q Adj_DII;
define sex / group "Sexe";
define Q / group "Quartile";
define Adj_DII / median;
run;
This is excellent and very simple.
PROC SUMMARY is the tool
UNTESTED CODE
proc summary data=project1.dii_q nway;
class sex q;
var adj_dii;
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;
var adj_dii;
output out=_stats_ pctlpts=12.5 37.5 62.5 87.5 pctlpre=oct;
run;
You can use this syntax in PROC SURVEYMEANS to compute the medians for each sex within each category:
Domain Q*sex;
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.
Thank you. Proc summary produced the results I wanted.
Thank you all for your effort.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.