BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sdixit
Obsidian | Level 7

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

@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.

View solution in original post

8 REPLIES 8
ballardw
Super User

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?

sdixit
Obsidian | Level 7

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.

Reeza
Super User

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

ballardw
Super User

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,

sdixit
Obsidian | Level 7

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 :

 

ABCFlag
5,7,8Y
9,7,4Y
8Y
9Y
9+Y
9-Y
10Y
5,6N
3,2N
Reeza
Super User

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;

 

 

sdixit
Obsidian | Level 7

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

Reeza
Super User

@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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1640 views
  • 0 likes
  • 3 in conversation