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

Dear, 

 

I am currently using multiple imputation for my dataset. Normally I report everything with mean and standard error.

But is there a way to calculate or analyse medians instead of means for the imputed dataset? 

 

Thank you!

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SAS_Rob
SAS Employee

You will need to use a Procedure that gives a standard error for the median so that you will be able to calculate the between and within imputation variance.  I think both Proc LIFETEST and SURVEYMEANS are the only procedures that do this.  I include an example below which uses the latter.

 

/*Sample Data Set that assumes Proc MI has already been run*/
data test;
do _imputation_=1 to 5;
do rep=1 to 100;
y=100+10*rannor(34211);
output;
end;
end;
run;
proc surveymeans data=test median;
by _imputation_;
var y;
ods output quantiles=stats;
run;

proc mianalyze data=stats;
modeleffects estimate;
stderr stderr;
run;

View solution in original post

13 REPLIES 13
japelin
Rhodochrosite | Level 12

try using proc univariate.

 

proc univariate data=sashelp.class;
  var age;
  output out=result MEDIAN=median;
run;

For other statistics, please refer to the following
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/procstat/procstat_univariate_syntax21.htm 

 

ablond
Fluorite | Level 6

I am currenlty using the following statement for calculating means of the imputed data. 

 

proc univariate data= test_imputed noprint;
var DAM ;
output out = test_imputed2 mean = DAM_new stderr= std_DAM ;
by intervention _Imputation_;
run;
proc mianalyze data=test_imputed edf=20;
modeleffects DAM_new;
stderr std_DAM;
by intervention;
run;

 

How should I adapt the proc mianalyze statement if I use median in the proc univariate? 

 

Thank you 

 

 

PaigeMiller
Diamond | Level 26

PROC MEANS and PROC SUMMARY also calculate medians and standard deviations/standard errors.

--
Paige Miller
ablond
Fluorite | Level 6

Hi ,

 

Thank you, could you please give an example of a code? I am using this code to calcute means for the imputed dataset. 

Does proc means and proc summary also work with proc mianalyze? 

 

proc univariate data= test_imputed noprint;
var DAM ;
output out = test_imputed2 mean = DAM_new stderr= std_DAM ;
by intervention _Imputation_;
run;
proc mianalyze data=test_imputed edf=20;
modeleffects DAM_new;
stderr std_DAM;
by intervention;
run;

 

PaigeMiller
Diamond | Level 26

Now I am confused. I did not interpret your original problem statement to be what your code is trying to do. I interpreted your original statement to mean that you did some form of multiple imputation, and after that you report means (or medians) and standard errors. But now it seems your code is doing things in the opposite order, computing medians and following that some form of missing value imputation.


So which is it?

--
Paige Miller
ablond
Fluorite | Level 6

Hi,

 

I imputed one variable with the PROC MI statement. Afterwards, I do the analyses 'by _Imputation' (which can be proc univariate, proc glm, etc - based on the analysis I need) , followed by a PROC MIANALYZE statement to gather the final results. 

 

Now I want to have medians (instead of means) of my imputed variable. But ofcourse taking into account the multiple imputation, I have to work with proc univariate followed by a PROC MIANALYZE. But I don't know how to adapt the code for medians (if this is even possible with proc mianalyze). 

 

 

 

PaigeMiller
Diamond | Level 26

Okay, thank you for the clarification. However, I have never used PROC MIANALYZE to report medians, so the answer is: I don't know the answer. However, hopefully someone will know, like maybe @Rick_SAS @StatDave 

--
Paige Miller
SAS_Rob
SAS Employee

You will need to use a Procedure that gives a standard error for the median so that you will be able to calculate the between and within imputation variance.  I think both Proc LIFETEST and SURVEYMEANS are the only procedures that do this.  I include an example below which uses the latter.

 

/*Sample Data Set that assumes Proc MI has already been run*/
data test;
do _imputation_=1 to 5;
do rep=1 to 100;
y=100+10*rannor(34211);
output;
end;
end;
run;
proc surveymeans data=test median;
by _imputation_;
var y;
ods output quantiles=stats;
run;

proc mianalyze data=stats;
modeleffects estimate;
stderr stderr;
run;

Rick_SAS
SAS Super FREQ

I like Rob's solution. However, there is another procedure that can estimate medians and provide standard errors. You can use PROC QUANTREG to estimate the median and std err and confidence intervals.

Here is an example that uses PROC QUANTREG:

ods exclude all;
proc quantreg data=test ci=sparsity;
   by _imputation_;
   model y=;
   ods output ParameterEstimates=PE;
run;
ods exclude none;

proc mianalyze data=stats;
   modeleffects estimate;
   stderr stderr;
run;

 

Ksharp
Super User
Rick,
proc univariate also could get CI of median.

proc univariate data=sashelp.heart CIQUANTDF CIQUANTNORMAL;
var weight;
run;
Rick_SAS
SAS Super FREQ

Yes. I originally mentioned that, but Rob reminded me that PROC MIANALYZE needs an estimate of a standard error, not a CI. UNIVARIATE only provides the CI.

ablond
Fluorite | Level 6

Thank you for this solution! 

 

could you explain me the following part of the script? :

do _imputation_=1 to 5;
do rep=1 to 100;
y=100+10*rannor(34211)

 

is it based on the amount of imputations (in my case 20)? Do I need to adapt this if I use 20 imputations? 

Where does y=100+10*rannor(34211) come from? 

SAS_Rob
SAS Employee

Hi

 

You can essentially ignore the first step in the sample program as I used it to generate a data set similar to what you would have gotten from Proc MI on your own data.  You would just pick up at the Proc SURVEYMEANS step that you would run on your own data.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 13 replies
  • 2432 views
  • 7 likes
  • 6 in conversation