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

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Combination and permutation

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

07-18-2016 01:59 PM - edited 07-18-2016 02:09 PM

Hi All,

Could you please let me know how to create a table having

all combination and permutation of (8,9-,9,9+,10) 5 numbers

taken 1, 2, 3, 4,5 at a time.

As the order matters here !!

Thanks

Accepted Solutions

Solution

07-20-2016
01:15 PM

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

07-20-2016 01:11 PM

sdixit wrote:

it is any number then flag ="y" . Varibale can have single digit or string of digits.

Then solution above should work, given your stated requirements.

All Replies

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

07-18-2016 02:22 PM

If order matters then you are looking at permutations, not combinations.

You say order matters, but what order?

Have you looked at the ALLPERM function?

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

07-18-2016 02:27 PM

I need to create string combined 2 out of 5 number (8,9-,9,9+,10).

then 3 , then 4 , and then 5.

and then need to create all possible permutaion of that combinations

Like example :

Conside ( 8 , 9 ) ( 8, 9+) , (8, 9-)

permutaion of above is reverse order.

Like Need to create another combination of 3 number among 5 and create all permuation of them.

Yes, I tried ALLPERM and ALL COMB

but didnot work out.

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

07-18-2016 04:02 PM

Please post what you've tried. How many numbers in your list?

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

07-18-2016 04:07 PM

Please show what you tried and exactly why it "did not work out". You may have been close. For instance when generating a data set you likely did not include an output statement in the correct place. Also you would need to create target variables to hold the results as desired.

And since you are looking to apparantly do permutation after combinations then you will likely need to go through a couple of datasteps.

And for curiosity's sake, what will you be doing with the resulting data set? Sometimes there are other approaches to the same end that are either more direct or less cumbersome.

Also,

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

07-20-2016 12:51 PM

Hi,

Sure! My motive is to create a flag when my variable matches with any number from ('8', '9+',' 9', '9-', '10') string.

So if there is any number present in my variable ABC , it should set the flag = "Y".

My data looks like :

ABC | Flag |

5,7,8 | Y |

9,7,4 | Y |

8 | Y |

9 | Y |

9+ | Y |

9- | Y |

10 | Y |

5,6 | N |

3,2 | N |

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

07-20-2016 01:05 PM

Generating all combinations/permutations would be a massive overkill. Does it have to contain all or any?

1. Create a temporary array with your set of lookup values

2. Use SCAN() to separate out components in ABC

3. Use WHICHC to find if the value is present.

```
data have;
input ABC $10.;
cards;
5,7,8
9,7,4
8
9
9+
9-
10
5,6
3,2
;
data want;
set have;
array lookup(5) $10 _temporary_ ('8' '9+' '9' '9-' '10');
n=countw(abc);
flag='N';
do i=1 to n;
part=strip(scan(abc, i, ","));
if whichc(part, of lookup(*))>0 then
flag='Y';
end;
keep abc flag ;
run;
```

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

07-20-2016 01:07 PM - edited 07-20-2016 01:08 PM

it is any number then flag ="y" . Varibale can have single digit or string of digits.

Solution

07-20-2016
01:15 PM

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

07-20-2016 01:11 PM

sdixit wrote:

it is any number then flag ="y" . Varibale can have single digit or string of digits.

Then solution above should work, given your stated requirements.