turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-16-2013 08:09 AM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-16-2013 08:41 AM

You say that you want to "order means for each simulation number," but I don't understand the connection to the %mean_will macro, which is not sorting anything.

The example data are

sim meanX1 meanX2 meanX3 meanX4 meanX5

1 1.85570 1.82321 1.85598 1.80608 1.81799

2 1.84527 1.82912 1.85502 1.85474 1.82042

What do you want the results to be, and why? Do you want each row to appear in sorted order? Do you want to run the %mean_will macro and then sort the resulting vector?

BTW, in the macro I notice that you are computing with x[u:v] when x is a matrix. Are you trying to work with the columns x[ ,u:v]?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-16-2013 09:06 AM

Yes the proc iml inside %mean_will macro looks at the mean values meanX1-meanX5 to see if they are all in a non-increasing order, if that's not the case it will take the average of those means that violate this restriction.

I want to be able to do this for each sim=1, 2, etc. The reason is that I'm doing some analysis where the alternative hypothesis is ordered this way. For this macro I want to be able to get the means computed/arranged as indicated in the proc iml but this done for each 'sim'. The whole macro works perfect when only 1 row is considered, problems start when I include several rows.

Yes, I'm working with the columns.

All in all it's more like this: For each sim (row) : The value in column 1 >= the value in column 2 >= etc.

I hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-16-2013 10:55 AM

I can't make sense of what your algorithm is doing, but here are some tips:

In the innermost loop, you have a computation that is equivalent to

w = x[u:v]#n[u:v];

a

This expression is incorrect when x is a matrix. Instead, you might consider a vector expression like this:

w = x[ ,u:v]#n[ ,u:v];

a[ ,v]=w[ ,+] / sum(n[u:v]);

where now a is now a matrix: a = j(nrow(x), ncol(x), .);

Then you have to do something with the MIN and MAX functions, so that you get the min and max for each row(?). Perhaps you can use something like this:

maxOfRows = a[ , <>];

minOfRows = a[ , ><];

In short, express everything as vectors and use subscript reduction operators. Subscript reduction operators are described here: Compute statistics for each row by using subscript operators - The DO Loop

Good luck.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

04-16-2013 11:02 AM

Thanks a lot, will look into your considerations carefully!