BookmarkSubscribeRSS Feed
psh23
Fluorite | Level 6

I am trying to run a MI with logistic regression. The proc MI and proc logistic run fine, but when I try to run the proc MIanalyze, it just runs forever until the computer freezes.

 

proc mi data=smokingr seed=550 out=p.outmi nimpute=10 minmaxiter=50;
class sex race smoking partnered ses smoke_d vitstat;
var sex race age2 yeardx_new smoke_d vitstat count ses partnered smoking;
fcs logistic(smoking ses/ link=glogit) logistic(partnered);
run;

 

proc logistic data=p.outmi;
class sex race(ref="NH White") smoking(ref="Yes") partnered(ref="Not partnered") ses(ref="Low") / param=ref;
model vitstat = sex race age2 ses partnered smoke_d smoking yeardx_new count;
by _imputation_;
ods output ParameterEstimates=parms;
run;

 

proc print data=parms; run;

 

proc mianalyze parms(classvar=classval)=parms;
title "pooled estimates SAS MI";
class sex race smoking partnered ses smoke_d;
modeleffects intercept sex race age2 ses partnered smoke_d smoking yeardx_new count;
ods output parameterestimates=MIestimates;
run;

28 REPLIES 28
Reeza
Super User

1. How big is your data? Number of rows or GB?

2. Does it work with sample data, try an example from the documentation?

http://documentation.sas.com/?docsetId=statug&docsetVersion=14.2&docsetTarget=statug_mianalyze_examp...

3. What version of SAS and SAS/STAT are you running?

psh23
Fluorite | Level 6

The example code runs perfectly. My data is small, about 2500 observations and its SAS 9.4

amcr729
Fluorite | Level 6

having the same problem. did you figure it out?

SAS_Rob
SAS Employee

Post your code and we can see if there is anything unusual about it.

amcr729
Fluorite | Level 6

Thanks, here is the code for the imputation process overall. It is when I run the code under /*3. pooling phase*/, highlighted in blue, that sas gets hung up, i.e. keeps running and never completes the procedure:

 


/*1. imputation phase*/
proc mi data=siya nimpute=20 out=mi_fcs;
class share give receive agyw drugs depression
ss worksite mobility pimp homeless money unsafe
disclose vs ed civil alcohol violrec viol;
fcs plots=trace(mean std);
var share give receive agyw drugs depression
ss worksite mobility pimp homeless money unsafe
disclose estigmasw estigmahiv astigmasw
astigmahiv pills303 pillsreceive303
pillsgive303 vs ed civil alcohol violrec viol ;
fcs discrim(share give receive agyw drugs depression
ss worksite mobility pimp homeless money unsafe
disclose vs ed civil alcohol violrec viol / classeffects=include) nbiter=100;
run;


/*2. analysis and pooling*/
proc genmod data=mi_fcs;
class pid civil (ref="0") depression (ref="0")
alcohol (ref="0") ed (ref="0") mobility (ref="0") unsafe (ref="0") money (ref="0") worksite (ref="0") /param=ref;
model vs=
pills303
agyw
ed
civil
alcohol
drugs
depression
mobility
worksite
pimp
violrec
homeless
money
unsafe
estigmasw
estigmahiv
astigmasw
astigmahiv disclose/Dist=poisson Link=log;
Repeated subject = pid / type=Ind PRINTMLE;
estimate 'pills303' pills303 1;
by _imputation_;
ods output ParameterEstimates=gm_fcs;
title 'VS on pills given and/or received with MI';
run;

 

/*3. pooling phase*/
TITLE " MULTIPLE IMPUTATION Linear REGRESSION - FCS";
PROC MIANALYZE parms(classvar=level)=gm_fcs;
class share give receive agyw drugs depression
ss worksite mobility pimp homeless money unsafe
disclose vs ed civil alcohol violrec viol;
MODELEFFECTS INTERCEPT share give receive agyw drugs depression
ss worksite mobility pimp homeless money unsafe
disclose estigmasw estigmahiv astigmasw
astigmahiv pills303 pillsreceive303
pillsgive303 vs ed civil alcohol violrec viol;/*all variables from all models*/
RUN;

 

SAS_Rob
SAS Employee

You have a bunch of extra variables on the CLASS statement in MIANALYZE.  You should only be using variables involved in the model from GENMOD.

 

PROC MIANALYZE parms(classvar=level)=gm_fcs;
class civil depression alcohol  ed  mobility  unsafe  money worksite ;
MODELEFFECTS INTERCEPT pills303
agyw
ed
civil
alcohol
drugs
depression
mobility
worksite
pimp
violrec
homeless
money
unsafe
estigmasw
estigmahiv
astigmasw
astigmahiv disclose;

run;

 

Also, since you are using a REPEATED statement in GENMOD you need to make sure that you are feeding the empirical estimates into MIANALYZE and not the MLEs.  In other words, your ODS OUTPUT statement is incorrect.  Use this one instead.

 

ods output GEEEmpPest=gm_fcs;

amcr729
Fluorite | Level 6

Thank you so much, that worked! But I am not getting the contrast estimate results I need when I run that PROC MIANALYZE code. do I include the estimate statement in it? Please advise, many thanks again.

SAS_Rob
SAS Employee

Combining ESTIMATE statement results can be done following this example.

data test;

do a=1 to 3;

do rep=1 to 10;

x=ranuni(123)*10;

if ranuni(234)>.55 then y=.;

else y=.46+.88*a+x+rannor(123);

output;

end;

end;

 

proc mi data=test out=outmi;

var a x y;

run;

ods trace on;

proc genmod data=outmi;

by _imputation_;

class a;

model y=a x;

estimate 'A1_v_A2' a 1 -1 0;*do not use spaces in the labels;

estimate 'A1_v_A3' a 1 0 -1;

ods output estimates=estimate_ds;

run;

proc sort data=estimate_ds;

by label _imputation_;

run;

proc mianalyze data=estimate_ds;

by label;

modeleffects LBetaEstimate;

stderr stderr;

run;

amcr729
Fluorite | Level 6

Thank you very much. I tried that code (below) and got the following error messages:

 

ERROR: Invalid reference value for ed.
ERROR: No valid observations due to invalid or missing values in the response, explanatory, offset,
       frequency, or weight variable.
NOTE: The above message was for the following BY group:
      pills303=0 Imputation Number=1
ERROR: Data set WORK.MI_FCS is not sorted in ascending sequence. The current BY group has pills303 =
       3.3333333333 and the next BY group has pills303 = 0.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: Output 'estimates' was not created.  Make sure that the output object name, label, or path
         is spelled correctly.  Also, verify that the appropriate procedure options are used to
         produce the requested output object.  For example, verify that the NOPRINT option is not
         used.

 

 

I do not know what could be wrong with "ed" -- it has four categories, 0-3.

"Pills303" is a continuous various (mean=0.63, range: 0-11.3)

 

 

Here is the code I ran per your guidance: 

proc genmod data=mi_fcs;
class pid civil (ref="0") depression (ref="0")
alcohol (ref="0") ed (ref="0") mobility (ref="0") unsafe (ref="0") money (ref="0") worksite (ref="0") /param=ref;
model vs=
pills303
agyw
ed
civil
alcohol
drugs
depression
mobility
worksite
pimp
violrec
homeless
money
unsafe
estigmasw
estigmahiv
astigmasw
astigmahiv disclose/Dist=poisson Link=log;
Repeated subject = pid / type=Ind ;
estimate 'pills303' pills303 1 -1 0;
by pills303 _imputation_;
ods output estimates=estimate_ds;
title 'VS on pills given and/or received with MI';
run;

 

Your help sorting this out would be greatly appreciated.

Reeza
Super User
ERROR: Data set WORK.MI_FCS is not sorted in ascending sequence. The current BY group has pills303 =
3.3333333333 and the next BY group has pills303 = 0.

That's the first issue to sort out, Once you fix that which errors are remaining?
SAS_Rob
SAS Employee

Why are you adding Pills303 to the BY statement?  To have the same variable on both the BY statement and in the MODEL statement is going to cause singularity issues since for each value of Pills303 it will fit a different model (and the values are constant). 

Likewise, the ESTIMATE statement does not make sense since there is only a single coefficient for Pills303 and it looks like you are trying to compare two separate levels..

amcr729
Fluorite | Level 6

thank you for pointing out the mistakes. I fixed those and it ran fine. But: the proc mianalyze results still don't give me the contrast estimate (prevalence ratio) that I need. I just get the beta (lbetaestimate). Is there a way to get that?

amcr729
Fluorite | Level 6

Hi - any thoughts on how to get the pooled contrast estimates from proc mianalyze? thanks so much in advance, hopefully this is the last question!

SAS_Rob
SAS Employee

You would need to add the EXP option to the ESTIMATE statement and then combine those estimates specifically.  Something like the example below would work.

data test;
seed=2534565;
do _imputation_=1 to 25;
do i=1 to 250;
do ind1=0 to 1;
do ind2=0 to 1;
logit=-1 + .05*ind1-.67*ind2;
p=exp(-logit)/(1+exp(-logit));
if ranuni(seed)>p then y=1; else y=0;
output;
end;
end;
end;
end;
run;
ods trace on;
proc genmod data=test;
model y=ind1 ind2 /dist=bin link=log;
by _Imputation_;
estimate 'Ind1 relative risk' ind1 1/exp;
estimate 'Ind2 relative risk' ind2 1/exp;
ods output Estimates=est_ds(where=(index(label,'Exp')=1));*Keeps the EXP values and their standard errors;
run;

proc sort data=est_ds;
by label _imputation_;
run;

proc mianalyze data=est_ds;
by label;
modeleffects LBetaEstimate;
stderr stderr;
run;

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register 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
  • 28 replies
  • 2119 views
  • 5 likes
  • 4 in conversation