BookmarkSubscribeRSS Feed
themanoj20080
Fluorite | Level 6

I am trying to create a macro which does simulation. Inside the macro I have PROC IML. Inside the PROC IML I have a DO LOOP. Inside that DO LOOP, how can I use SAS procedure? I would really appreciate an simple example of this.

7 REPLIES 7
SASKiwi
PROC Star

SAS Procedures cannot be run inside each other, they have to run on their own sequentially - one after another.

 

You could have a macro loop that runs PROC IML, then following that another PROC and keep repeating that sequence.

themanoj20080
Fluorite | Level 6

Actually, I have a macro to start with then I have proc iml. 

%macro mymacro(mydata,X,Y,M);
proc corr data=&mydata outs=M;
var &X &Y;
run;

/*Now let's begin Proc IML*/
proc iml;
use &mydata; read all var{&X} into xvar;
use &mydata; read all var{&Y} into yvar;
create combined var{xvar,yvar};
append;
close combined;

use M;
read all var {&Y};
close M;
RR = &Y[4];

print RR;
AA=j(&M,1,0);
quit;

proc iml;
do i = 1 to &M;
	U=uniform(repeat(0,nrow(&X),1));
	create together var{&X,U};
	append;
	close together;
	
	proc sort data=together;
	by U;
	run;

	data together;
	merge together &mydata;
	run;
	
	
	proc corr data=together spearman outs=MM noprint;
	var &X &Y;
	run;
	

	use MM;
	read all var {&Y};
	close MM;
	R = &Y[4];
	*print R;
	
	if abs(R) > RR then AA[i]=1;
	else  AA[i]=0;
	

end;
quit;
p_value=mean(AA);
print p_value;

%mend mymacro;
themanoj20080
Fluorite | Level 6

What is wrong with the code that I just posted? I cannot get it to work.

Cynthia_sas
Diamond | Level 26
Hi:
The SAS IML forum is here: https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/bd-p/sas_iml you might have better response from participants who are using IML.
Cynthia
SASKiwi
PROC Star

@themanoj20080 - You have PROC SORT, a DATA step and PROC CORR code inside a PROC IML step. A PROC IML step can only contain PROC IML code and nothing else. Removing PROC SORT, the DATA step and PROC CORR will get you closer to a working program.

themanoj20080
Fluorite | Level 6

Okay. I removed those procedures from proc iml. I quitted proc iml before the do loop and started with

%do i = 1 %to &M;

 

But still it is not working. I think the problem now is with use MM part.