DATA Step, Macro, Functions and more

number combinations using sas

Accepted Solution Solved
Reply
Contributor
Posts: 71
Accepted Solution

number combinations using sas

Hi,

I am trying to get all possible 5 digit combinations of numbers starting from 0 to 4. I am not sure how to start or if it is doable. Has anybody done something like this before? Thanks in advance for your help!

Here is what i am looking for

00000

00001

00002

.

.

.

.

44442

44443

44444


Accepted Solutions
Solution
‎09-24-2012 08:09 PM
Super Contributor
Posts: 1,636

Re: number combinations using sas

data have;

length all $ 5;

  do i=0 to 4;

    do j=0 to 4;

   do k=0 to 4;

     do l=0 to 4;

   do m=0 to 4;

  all=cats(i,j,k,l,m);

  output;

  end;

  end;

  end;

  end;

  end;

  keep all;

  run;

  proc print;run;

View solution in original post


All Replies
Solution
‎09-24-2012 08:09 PM
Super Contributor
Posts: 1,636

Re: number combinations using sas

data have;

length all $ 5;

  do i=0 to 4;

    do j=0 to 4;

   do k=0 to 4;

     do l=0 to 4;

   do m=0 to 4;

  all=cats(i,j,k,l,m);

  output;

  end;

  end;

  end;

  end;

  end;

  keep all;

  run;

  proc print;run;

Respected Advisor
Posts: 4,935

Re: number combinations using sas

If you want numbers :

data test(keep=x);

format x z5.;

digits=5;

base=5;

do i = 0 to base**digits-1;

     x = 0;

     y = i;

     do j = 1 to digits;

          x = x + mod(y,base)*10**(j-1);

          y = int(y/base);

          end;

     output;

     end;

run;

PG

PG
Contributor
Posts: 71

Re: number combinations using sas

Both answers worked. Thank you so much!!

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 223 views
  • 5 likes
  • 3 in conversation