I have a macro which orders means (ascending/descending) using PROC IML. But I want to do this for each simulation number. Is it possible to do this, given that in the usual data step I can use the 'BY statement'?
Here is it this SAS macro and a small dataset is attached (with variables sim, meanX1--meanX5). This macro is support to arrange the means in a descending order per 'sim'.
%macro mean_will(numbersim=, J1=, J2=, J3=, J4=, J5=, df=);
proc iml;
start MLE(x,n);
k=ncol(x);
m=j(1,k,.);
a=j(1,k,.);
c=j(1,k,.);
do i=1 to k;
do u=1 to i;
do v=i to k;
a=sum(x[u:v]#n[u:v])/sum(n[u:v]);
end;
c=max(a);
a=j(1,k,.);
end;
m=min(c);
c=j(1,k,.);
end;
return(m);
finish;
use meanXit;
read all into Xmat;
x=Xmat[,2]||Xmat[,3]||Xmat[,4]||Xmat[,5]||Xmat[,6];
n={&J1 &J2 &J3 &J4 &J5};
m=MLE(x,n);
create meanX from m;
append from m;
run;
quit;
%mend;
%mean_will(numbersim=2, J1=7, J2=2, J3=2, J4=2, J5=2, df=20);