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.
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.
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;
What is wrong with the code that I just posted? I cannot get it to work.
@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.
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.
Let's move this conversation to the IML Community:
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.