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
SAS Super FREQ
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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 942 views
  • 0 likes
  • 4 in conversation