BookmarkSubscribeRSS Feed
pengznuc
Fluorite | Level 6

Hello, I am trying to do some imputation with SAS, and repeated with fixed seed. I tried a simple one. it works. 

 

But when I change the data and codes:  1. x and y are category var while v and w are continuous var; 2 add out=out_data; 3. change imputation method from MCMC to FCS;  It did not work. 

 

I am a beginner for MACRO. Could anyone help me for this problem? 

 

Many thanks

 

 

/*work*/
data eq;
input y x z w;
cards;
1 23 45 19
0 32 20 .
1 67 . .
1 . . .
;
run;

%macro mi(in_data);
	proc mi data = &in_data nimpute=&n_imp seed= &&my_seed&i;
		mcmc chain=multiple  initial=em(itprint);
   		var y x z w;
	run;
%mend mi;

%macro try(in_data,n_imp,in_seed,n_boot);
	data seed_long(drop=i);
  		call streaminit(&in_seed);
  		do i = 1 to &n_boot;
    		x_seed = floor(rand("Uniform")*500000); output;
  		end;
	run;

 	data _null_;
 		set seed_long;
 		call symput('my_seed'|| compress(put(_n_,8.)), x_seed);
 	run;

   %let i=1;
   %do %until (&i>&n_boot) ;
	  %mi(&in_data)
      %let i = %eval(&i+1);
   %end;
%mend try;

%try(eq,5,123,3)
%put _global_;


/*not work*/
data eq1;
input ID y x z w;
cards;
1 1 23 0 19
2 0 32 1 .
3 1 67 . .
3 1 . 1 3
;
run;

%macro mi(in_data);
	proc mi data = &in_data  out=out_data nimpute=&n_imp seed= &&my_seed&i;
		CLASS y;
		 FCS REG (x w)
     	LOGISTIC (y );
 	VAR y x z w;
	run;
%mend mi;

proc genmod data = out_data ; 
class ID;
model y = x z w/dist=bin; 
repeated subject=ID/type=ind;
by _imputation_; 
ods output ParameterEstimates=mvn; 
run; quit;


proc mianalyze parms=mvn;
modeleffects x;
ods output ParameterEstimates=sim_y;
run;


%macro try(in_data,n_imp,in_seed,n_boot);
	data seed_long(drop=i);
  		call streaminit(&in_seed);
  		do i = 1 to &n_boot;
    		x_seed = floor(rand("Uniform")*500000); output;
  		end;
	run;

 	data _null_;
 		set seed_long;
 		call symput('my_seed'|| compress(put(_n_,8.)), x_seed);
 	run;

   %let i=1;
   %do %until (&i>&n_boot) ;
	  %mi(&in_data)
      %let i = %eval(&i+1);
   %end;
%mend try;

%try(eq1,5,123,3)
%put _global_;
1 REPLY 1
RobPratt
SAS Super FREQ

PROC MI is in SAS/STAT, so it is better to ask in that community.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Discussion stats
  • 1 reply
  • 1345 views
  • 0 likes
  • 2 in conversation