BookmarkSubscribeRSS Feed
ATudhope
Calcite | Level 5

Hi, I hope someone can help me.

I need to enumerate all combinations of 36 from 42 in SAS IML. I have the loops as such:

do i  = 1 to ns-1;

       do j = i+1 to ns;

               do m = j+1 to ns;

                      do n = m+1 to ns;

                           Options[k,1] = i;

                           Options[k,2] = j;

                           Options[k,3] = m;

                           Options[k,4] = n;

                           Options[k,5] = o;

                           k=k+1;

                           end;

                 end;

           end;

end;

Which gives all combinations of 4 from the 42. Is there an easier way for SAS to do this for me rather than adding in so many do loops?

I need this for an allocation problem in which I am looking for the optimal assignment of swimmers to relay teams. 

Thank you

2 REPLIES 2
Rick_SAS
SAS Super FREQ

Use the ALLCOMB function:

 

proc iml;

n=comb(42,36);      /* how many rows will you get? */

print n;

v = allcomb(42,36); /* create n x 36 matrix */

print (v[1:5,]);    /* print first 5 rows */

For details and other examples in IML, see

Generate combinations in SAS - The DO Loop

For DATA step, see

Lexicographic combinations in SAS - The DO Loop

Ksharp
Super User

use function ALLCOMB.

n = 4;
k = 2;
c = allcomb(n, k);
print c;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 866 views
  • 0 likes
  • 3 in conversation