BookmarkSubscribeRSS Feed
pengznuc
Fluorite | Level 6
/*work*/
data eq;
input y z x 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_;

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; 4. Add proc genmod  and proc mianalyze, It did not work. 

 

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

 

Many thanks

3 REPLIES 3
ballardw
Super User

"It didn't work" is awful vague.

Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.

No output? Post any log in a code box.

Unexpected output? Provide input data in the form of a dataset, the actual results and the expected results. Data should be in the form of a data step. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

When working with macros you want to turn on the macro debug options with

Options mprint symbolgen mlogic;

before running the code so you can see what the macro language is generating. If you get error messages the errors will be in better proximity to the actual problem.

 

reset the options with

Options nomprint nosymbolgen nomlogic;

 

 

pengznuc
Fluorite | Level 6

Thanks for your suggestion. But I did provide input sample data in the form of a dataset, which is eq and eq1. I think it will be helpful to demonstrate the mistake if someone runs the code. 

 

There are several errors. 

 

595 proc genmod data = out_data ;
ERROR: File WORK.OUT_DATA.DATA does not exist.
596 class ID;
ERROR: No data set open to look up variables.
597 model y = x z w/dist=bin;
ERROR: No data set open to look up variables.
598 repeated subject=ID/type=ind;
599 by _imputation_;
ERROR: No data set open to look up variables.
600 ods output ParameterEstimates=mvn;
601 run;


604 proc mianalyze parms=mvn;
ERROR: File WORK.MVN.DATA does not exist.

WARNING: Output 'ParameterEstimates' 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.


ERROR: Not enough observations to fit regression models for variable z with an FCS regression
method.
NOTE: The SAS System stopped processing this step because of errors.

 

CP2
Pyrite | Level 9 CP2
Pyrite | Level 9
It looks like you need to place the open code after the macro definitions and after executing the try macro. Otherwise the proc genmod is looking for the out_data and it doesn't exist until the MI macro is executed.

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;



%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)



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;


%put _global_;

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
  • 3 replies
  • 1893 views
  • 0 likes
  • 3 in conversation