Need SAS Logic to list all number combinations?

Reply
Occasional Contributor
Posts: 11

Need SAS Logic to list all number combinations?

Dear Folks,

Request your help in SAS logic to list all number combinations. For example, lets say I have 12345. We know we can figure out several combinations such as 12345,21345, 31245,41235,51234..................and so on. I would like a SAS logic that would pick and list all combinations. Your help would be most appreciated. Merry Christmas. Thanks

Super User
Posts: 5,434

Re: Need SAS Logic to list all number combinations?

Posted in reply to Nav_Sweeney

This sounds like a mathematical quiz, rather than a business requirement...?

Like most programming, there are several ways to accomplish this. On could involve arrays and do loop in the data step. If you want it dynamic (like number of number) you might need to use macro logic.

Data never sleeps
Respected Advisor
Posts: 3,799

Re: Need SAS Logic to list all number combinations?

Posted in reply to Nav_Sweeney

Looks like you are want permutations.  From the online documentation.

SAS provides three functions               or CALL routines for generating all permutations:                              
  • ALLPERM generates all possible permutations of the values, missing or non-missing, of several variables.                              Each permutation is formed from the previous permutation by interchanging                              two consecutive values.                           
  • LEXPERM generates all distinct permutations of the non-missing values of several variables. The                              permutations are generated in lexicographic order.                          
  • LEXPERK generates all distinct permutations of K of the non-missing values of N variables. The permutations                              are generated in lexicographic order.                          
ALLPERM is the fastest               of these functions and CALL routines. LEXPERK is the slowest.           
PROC Star
Posts: 1,167

Re: Need SAS Logic to list all number combinations?

Posted in reply to Nav_Sweeney

Another option is to use PROC PLAN.

Tom

Occasional Contributor
Posts: 11

Re: Need SAS Logic to list all number combinations?

Hi Tom,

Thanks very much indeed. Worked perfectly well.

Cheers,

Nav

Ask a Question
Discussion stats
  • 4 replies
  • 367 views
  • 9 likes
  • 4 in conversation