BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Prest
Fluorite | Level 6

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.

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Zard
SAS Employee

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

 

Domain Q*sex;

View solution in original post

6 REPLIES 6
JeanDo
Obsidian | Level 7

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;
Prest
Fluorite | Level 6

This is excellent and very simple.

PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller
Zard
SAS Employee

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

 

Domain Q*sex;

Prest
Fluorite | Level 6

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. 

Prest
Fluorite | Level 6

Thank you. Proc summary produced the results I wanted. 

 

Thank you all for your effort.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

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